1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26 package com.intel.bluetooth;
27
28 import java.io.IOException;
29
30
31
32
33
34 class EmulatorL2CAPClient extends EmulatorLinkedConnection {
35
36 private int receiveMTU;
37
38 private int transmitMTU;
39
40 EmulatorL2CAPClient(EmulatorLocalDevice localDevice, long handle) {
41 super(localDevice, handle);
42 }
43
44 void connect(BluetoothConnectionParams params, int receiveMTU, int transmitMTU) throws IOException {
45 connectVerify(params);
46 this.connectionHandle = localDevice.getDeviceManagerService().l2Connect(localDevice.getAddress(),
47 params.address, params.channel, params.authenticate, params.encrypt, receiveMTU, params.timeout);
48 this.remoteAddress = params.address;
49 this.receiveMTU = receiveMTU;
50 this.transmitMTU = transmitMTU;
51 int remoteDeviceReceiveMTU = localDevice.getDeviceManagerService().l2RemoteDeviceReceiveMTU(
52 localDevice.getAddress(), this.connectionHandle);
53 if (this.transmitMTU == -1) {
54 this.transmitMTU = remoteDeviceReceiveMTU;
55 } else if (this.transmitMTU < remoteDeviceReceiveMTU) {
56
57 } else {
58 this.transmitMTU = remoteDeviceReceiveMTU;
59 }
60 }
61
62 void connect(long remoteAddress, long connectionHandle, int receiveMTU, int transmitMTU) throws IOException {
63 super.connect(remoteAddress, connectionHandle);
64 this.receiveMTU = receiveMTU;
65 this.transmitMTU = transmitMTU;
66 }
67
68 int getReceiveMTU() throws IOException {
69 return receiveMTU;
70 }
71
72 int getTransmitMTU() throws IOException {
73 return transmitMTU;
74 }
75
76 boolean ready() throws IOException {
77 return localDevice.getDeviceManagerService().l2Ready(localDevice.getAddress(), this.connectionHandle);
78 }
79
80 int receive(byte[] inBuf) throws IOException {
81 byte[] packetData = localDevice.getDeviceManagerService().l2Receive(localDevice.getAddress(),
82 this.connectionHandle, this.receiveMTU);
83 int length = packetData.length;
84 if (length > inBuf.length) {
85 length = inBuf.length;
86 }
87 System.arraycopy(packetData, 0, inBuf, 0, length);
88 return length;
89 }
90
91 void send(byte[] data) throws IOException {
92 if (data.length > transmitMTU) {
93 byte[] b = new byte[transmitMTU];
94 System.arraycopy(data, 0, b, 0, transmitMTU);
95 data = b;
96 }
97 localDevice.getDeviceManagerService().l2Send(localDevice.getAddress(), this.connectionHandle, data);
98 }
99
100 }