BlackOneとAndroidの連携デモプログラム AndroidAccessoryを改造してBlackOneとAndroidが連携できるようにしました。 サポートしているのは、デモアプリの ”Buttons” B1-SW1, B2-SW2, B3-SW3 ”LED2” RGB-LED のみです。 LCDに表示するイメージをマイクロSDカードに入れてLCDのソケットに挿入しておく必要があります。 イメージは、320X240ドットで”\Image”という名前のフォルダの直下に”10.jpg”という名前で入れてください。

Dependencies:   TextLCD mbed

Committer:
techand
Date:
Fri Dec 23 04:33:33 2011 +0000
Revision:
0:7b556109fd46

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
techand 0:7b556109fd46 1 /*
techand 0:7b556109fd46 2 Copyright (c) 2010 Peter Barrett
techand 0:7b556109fd46 3
techand 0:7b556109fd46 4 Permission is hereby granted, free of charge, to any person obtaining a copy
techand 0:7b556109fd46 5 of this software and associated documentation files (the "Software"), to deal
techand 0:7b556109fd46 6 in the Software without restriction, including without limitation the rights
techand 0:7b556109fd46 7 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
techand 0:7b556109fd46 8 copies of the Software, and to permit persons to whom the Software is
techand 0:7b556109fd46 9 furnished to do so, subject to the following conditions:
techand 0:7b556109fd46 10
techand 0:7b556109fd46 11 The above copyright notice and this permission notice shall be included in
techand 0:7b556109fd46 12 all copies or substantial portions of the Software.
techand 0:7b556109fd46 13
techand 0:7b556109fd46 14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
techand 0:7b556109fd46 15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
techand 0:7b556109fd46 16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
techand 0:7b556109fd46 17 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
techand 0:7b556109fd46 18 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
techand 0:7b556109fd46 19 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
techand 0:7b556109fd46 20 THE SOFTWARE.
techand 0:7b556109fd46 21 */
techand 0:7b556109fd46 22
techand 0:7b556109fd46 23
techand 0:7b556109fd46 24 #include <stdio.h>
techand 0:7b556109fd46 25 #include <stdlib.h>
techand 0:7b556109fd46 26 #include <stdio.h>
techand 0:7b556109fd46 27 #include <string.h>
techand 0:7b556109fd46 28
techand 0:7b556109fd46 29 #include "Utils.h"
techand 0:7b556109fd46 30 #include "hci.h"
techand 0:7b556109fd46 31
techand 0:7b556109fd46 32 #define L2CAP_COMMAND_REJ 0x01
techand 0:7b556109fd46 33 #define L2CAP_CONN_REQ 0x02
techand 0:7b556109fd46 34 #define L2CAP_CONN_RSP 0x03
techand 0:7b556109fd46 35 #define L2CAP_CONF_REQ 0x04
techand 0:7b556109fd46 36 #define L2CAP_CONF_RSP 0x05
techand 0:7b556109fd46 37 #define L2CAP_DISCONN_REQ 0x06
techand 0:7b556109fd46 38 #define L2CAP_DISCONN_RSP 0x07
techand 0:7b556109fd46 39 #define L2CAP_ECHO_REQ 0x08
techand 0:7b556109fd46 40 #define L2CAP_ECHO_RSP 0x09
techand 0:7b556109fd46 41 #define L2CAP_INFO_REQ 0x0a
techand 0:7b556109fd46 42 #define L2CAP_INFO_RSP 0x0b
techand 0:7b556109fd46 43
techand 0:7b556109fd46 44
techand 0:7b556109fd46 45 /* L2CAP command codes */
techand 0:7b556109fd46 46 const char* L2CAP_ComandCodeStr(int c)
techand 0:7b556109fd46 47 {
techand 0:7b556109fd46 48 switch (c)
techand 0:7b556109fd46 49 {
techand 0:7b556109fd46 50 case L2CAP_COMMAND_REJ: return "L2CAP_COMMAND_REJ";
techand 0:7b556109fd46 51 case L2CAP_CONN_REQ: return "L2CAP_CONN_REQ";
techand 0:7b556109fd46 52 case L2CAP_CONN_RSP: return "L2CAP_CONN_RSP";
techand 0:7b556109fd46 53 case L2CAP_CONF_REQ: return "L2CAP_CONF_REQ";
techand 0:7b556109fd46 54 case L2CAP_CONF_RSP: return "L2CAP_CONF_RSP";
techand 0:7b556109fd46 55 case L2CAP_DISCONN_REQ: return "L2CAP_DISCONN_REQ";
techand 0:7b556109fd46 56 case L2CAP_DISCONN_RSP: return "L2CAP_DISCONN_RSP";
techand 0:7b556109fd46 57 case L2CAP_ECHO_REQ: return "L2CAP_ECHO_REQ";
techand 0:7b556109fd46 58 case L2CAP_ECHO_RSP: return "L2CAP_ECHO_RSP";
techand 0:7b556109fd46 59 case L2CAP_INFO_REQ: return "L2CAP_INFO_REQ";
techand 0:7b556109fd46 60 case L2CAP_INFO_RSP: return "L2CAP_INFO_RSP";
techand 0:7b556109fd46 61 }
techand 0:7b556109fd46 62 return "unknown";
techand 0:7b556109fd46 63 }
techand 0:7b556109fd46 64
techand 0:7b556109fd46 65 typedef struct
techand 0:7b556109fd46 66 {
techand 0:7b556109fd46 67 u16 handle;
techand 0:7b556109fd46 68 u16 length; // total
techand 0:7b556109fd46 69 u16 l2capLength; // length -4
techand 0:7b556109fd46 70 u16 cid; // Signaling packet CID = 1
techand 0:7b556109fd46 71 u8 data[64]; // Largest thing to send!!! todo
techand 0:7b556109fd46 72 } L2CAPData;
techand 0:7b556109fd46 73
techand 0:7b556109fd46 74 typedef struct
techand 0:7b556109fd46 75 {
techand 0:7b556109fd46 76 u16 handle;
techand 0:7b556109fd46 77 u16 length; // total
techand 0:7b556109fd46 78 u16 l2capLength; // length -4
techand 0:7b556109fd46 79 u16 cid; // Signaling packet CID = 1
techand 0:7b556109fd46 80
techand 0:7b556109fd46 81 // Payload
techand 0:7b556109fd46 82 u8 cmd; //
techand 0:7b556109fd46 83 u8 id;
techand 0:7b556109fd46 84 u16 cmdLength; // total-8
techand 0:7b556109fd46 85 u16 params[4]; // Params
techand 0:7b556109fd46 86 } L2CAPCmd;
techand 0:7b556109fd46 87
techand 0:7b556109fd46 88 void printf(const BD_ADDR* addr);
techand 0:7b556109fd46 89
techand 0:7b556109fd46 90 //
techand 0:7b556109fd46 91 void BTDevice::Init()
techand 0:7b556109fd46 92 {
techand 0:7b556109fd46 93 memset(&_info,0,sizeof(inquiry_info));
techand 0:7b556109fd46 94 _handle = 0;
techand 0:7b556109fd46 95 _name[0] = 0;
techand 0:7b556109fd46 96 _state = 0;
techand 0:7b556109fd46 97 }
techand 0:7b556109fd46 98
techand 0:7b556109fd46 99 // virtual SocketHandler
techand 0:7b556109fd46 100 int BTDevice::Open(SocketInternal* sock, SocketAddrHdr* addr)
techand 0:7b556109fd46 101 {
techand 0:7b556109fd46 102 printf("Call to BTDevice Open \r\n");
techand 0:7b556109fd46 103 L2CAPSocket* s = (L2CAPSocket*)sock;
techand 0:7b556109fd46 104 L2CAPAddr* a = (L2CAPAddr*)addr;
techand 0:7b556109fd46 105 s->scid = 0x40 + sock->ID-1; // are these reserved?
techand 0:7b556109fd46 106 s->dcid = 0;
techand 0:7b556109fd46 107 Connect(s->scid,a->psm);
techand 0:7b556109fd46 108 return sock->ID;
techand 0:7b556109fd46 109 }
techand 0:7b556109fd46 110
techand 0:7b556109fd46 111 // virtual SocketHandler
techand 0:7b556109fd46 112 int BTDevice::Create(SocketInternal* sock, SocketAddrHdr* addr)
techand 0:7b556109fd46 113 {
techand 0:7b556109fd46 114 printf("Call to BTDevice Create \r\n");
techand 0:7b556109fd46 115 L2CAPSocket* s = (L2CAPSocket*)sock;
techand 0:7b556109fd46 116 L2CAPAddr* a = (L2CAPAddr*)addr;
techand 0:7b556109fd46 117
techand 0:7b556109fd46 118 //Connect(s->scid,a->psm);
techand 0:7b556109fd46 119 return sock->ID;
techand 0:7b556109fd46 120 }
techand 0:7b556109fd46 121
techand 0:7b556109fd46 122 int BTDevice::Accept(SocketInternal* sock, SocketAddrHdr* addr)
techand 0:7b556109fd46 123 {
techand 0:7b556109fd46 124 printf("Call to BTDevice Accept \r\n");
techand 0:7b556109fd46 125 L2CAPSocket* s = (L2CAPSocket*)sock;
techand 0:7b556109fd46 126 L2CAPAddr* a = (L2CAPAddr*)addr;
techand 0:7b556109fd46 127
techand 0:7b556109fd46 128
techand 0:7b556109fd46 129 printf("ID = %d scid = %d dcid = %d \r\n",sock->ID, s->scid, s->dcid);
techand 0:7b556109fd46 130
techand 0:7b556109fd46 131 return sock->ID;
techand 0:7b556109fd46 132 }
techand 0:7b556109fd46 133
techand 0:7b556109fd46 134
techand 0:7b556109fd46 135
techand 0:7b556109fd46 136
techand 0:7b556109fd46 137 // virtual SocketHandler
techand 0:7b556109fd46 138 int BTDevice::Send(SocketInternal* sock, const u8* data, int len)
techand 0:7b556109fd46 139 {
techand 0:7b556109fd46 140 printf("Call to BTDevice Send \r\n");
techand 0:7b556109fd46 141 L2CAPData d;
techand 0:7b556109fd46 142 L2CAPSocket* s = (L2CAPSocket*)sock;
techand 0:7b556109fd46 143
techand 0:7b556109fd46 144 d.handle = _handle | 0x2000;
techand 0:7b556109fd46 145 d.length = 4 + len;
techand 0:7b556109fd46 146 d.l2capLength = len;
techand 0:7b556109fd46 147 d.cid = s->dcid;
techand 0:7b556109fd46 148
techand 0:7b556109fd46 149 if (len > 64)
techand 0:7b556109fd46 150 return -1;
techand 0:7b556109fd46 151 memcpy(d.data,data,len);
techand 0:7b556109fd46 152 return Send((u8*)&d,len+8);
techand 0:7b556109fd46 153 }
techand 0:7b556109fd46 154
techand 0:7b556109fd46 155 // virtual SocketHandler
techand 0:7b556109fd46 156 int BTDevice::Close(SocketInternal* sock)
techand 0:7b556109fd46 157 {
techand 0:7b556109fd46 158 printf("L2CAP close %d\r\n",sock->ID);
techand 0:7b556109fd46 159 L2CAPSocket* s = (L2CAPSocket*)sock;
techand 0:7b556109fd46 160 return Disconnect(s->scid,s->dcid);
techand 0:7b556109fd46 161 }
techand 0:7b556109fd46 162
techand 0:7b556109fd46 163 L2CAPSocket* BTDevice::SCIDToSocket(int scid)
techand 0:7b556109fd46 164 {
techand 0:7b556109fd46 165 return (L2CAPSocket*)GetSocketInternal(scid-0x40+1);
techand 0:7b556109fd46 166 }
techand 0:7b556109fd46 167
techand 0:7b556109fd46 168 int BTDevice::Send(const u8* data, int len)
techand 0:7b556109fd46 169 {
techand 0:7b556109fd46 170 printfBytes("L2CP send: ",data,len);
techand 0:7b556109fd46 171 _transport->ACLSend(data,len);
techand 0:7b556109fd46 172 return 0;
techand 0:7b556109fd46 173 }
techand 0:7b556109fd46 174
techand 0:7b556109fd46 175 int BTDevice::Send(u8 c, u8 id, u16* params, int count)
techand 0:7b556109fd46 176 {
techand 0:7b556109fd46 177 L2CAPCmd cmd;
techand 0:7b556109fd46 178 cmd.handle = _handle | 0x2000;
techand 0:7b556109fd46 179 cmd.length = 8 + count*2;
techand 0:7b556109fd46 180
techand 0:7b556109fd46 181 cmd.l2capLength = cmd.length-4;
techand 0:7b556109fd46 182 cmd.cid = 1; // Signaling packet
techand 0:7b556109fd46 183
techand 0:7b556109fd46 184 cmd.cmd = c;
techand 0:7b556109fd46 185 cmd.id = id;
techand 0:7b556109fd46 186 cmd.cmdLength = count*2;
techand 0:7b556109fd46 187 for (int i = 0; i < count; i++)
techand 0:7b556109fd46 188 cmd.params[i] = params[i];
techand 0:7b556109fd46 189 return Send((u8*)&cmd,cmd.length+4);
techand 0:7b556109fd46 190 }
techand 0:7b556109fd46 191
techand 0:7b556109fd46 192 int BTDevice::Connect(int scid, int psm)
techand 0:7b556109fd46 193 {
techand 0:7b556109fd46 194 u16 p[2];
techand 0:7b556109fd46 195 p[0] = psm;
techand 0:7b556109fd46 196 p[1] = scid;
techand 0:7b556109fd46 197 return Send(L2CAP_CONN_REQ,_txid++,p,2);
techand 0:7b556109fd46 198 }
techand 0:7b556109fd46 199
techand 0:7b556109fd46 200 int BTDevice::Disconnect(int scid, int dcid)
techand 0:7b556109fd46 201 {
techand 0:7b556109fd46 202 u16 p[2];
techand 0:7b556109fd46 203 p[0] = dcid;
techand 0:7b556109fd46 204 p[1] = scid;
techand 0:7b556109fd46 205 return Send(L2CAP_DISCONN_REQ,_txid++,p,2);
techand 0:7b556109fd46 206 }
techand 0:7b556109fd46 207
techand 0:7b556109fd46 208 int BTDevice::ConfigureRequest(int dcid)
techand 0:7b556109fd46 209 {
techand 0:7b556109fd46 210 u16 p[4];
techand 0:7b556109fd46 211 p[0] = dcid;
techand 0:7b556109fd46 212 p[1] = 0;
techand 0:7b556109fd46 213 p[2] = 0x0201; // Options
techand 0:7b556109fd46 214 p[3] = 0x02A0; // 672
techand 0:7b556109fd46 215 return Send(L2CAP_CONF_REQ,_txid++,p,4);
techand 0:7b556109fd46 216 }
techand 0:7b556109fd46 217
techand 0:7b556109fd46 218 int BTDevice::ConfigureResponse(u8 rxid, int dcid)
techand 0:7b556109fd46 219 {
techand 0:7b556109fd46 220 u16 p[3];
techand 0:7b556109fd46 221 p[0] = dcid;
techand 0:7b556109fd46 222 p[1] = 0;
techand 0:7b556109fd46 223 p[2] = 0;
techand 0:7b556109fd46 224 return Send(L2CAP_CONF_RSP,rxid,p,3);
techand 0:7b556109fd46 225 }
techand 0:7b556109fd46 226
techand 0:7b556109fd46 227 int BTDevice::DisconnectResponse(u8 rxid, int scid, int dcid)
techand 0:7b556109fd46 228 {
techand 0:7b556109fd46 229 u16 p[2];
techand 0:7b556109fd46 230 p[0] = dcid;
techand 0:7b556109fd46 231 p[1] = scid;
techand 0:7b556109fd46 232 return Send(L2CAP_DISCONN_RSP,rxid,p,2);
techand 0:7b556109fd46 233 }
techand 0:7b556109fd46 234
techand 0:7b556109fd46 235 int BTDevice::AcceptResponse(u8 rxid, int scid, int dcid)
techand 0:7b556109fd46 236 {
techand 0:7b556109fd46 237 printf("Connection accepted \r\n");
techand 0:7b556109fd46 238 u16 p[4];
techand 0:7b556109fd46 239 p[0] = scid;
techand 0:7b556109fd46 240 p[1] = dcid;
techand 0:7b556109fd46 241 p[2] = L2CAP_CONN_SUCCESS;
techand 0:7b556109fd46 242 p[3] = 0;
techand 0:7b556109fd46 243
techand 0:7b556109fd46 244 return Send(L2CAP_CONN_RSP,rxid,p,4);
techand 0:7b556109fd46 245
techand 0:7b556109fd46 246 }
techand 0:7b556109fd46 247
techand 0:7b556109fd46 248 int BTDevice::RefuseResponse(u8 rxid)
techand 0:7b556109fd46 249 {
techand 0:7b556109fd46 250 printf("Connection refused \r\n");
techand 0:7b556109fd46 251 u16 p[2];
techand 0:7b556109fd46 252 p[0] = L2CAP_CONN_REF_PSM;
techand 0:7b556109fd46 253 p[1] = 0;
techand 0:7b556109fd46 254
techand 0:7b556109fd46 255 return Send(L2CAP_CONN_RSP,rxid,p,2);
techand 0:7b556109fd46 256 }
techand 0:7b556109fd46 257
techand 0:7b556109fd46 258
techand 0:7b556109fd46 259 //int BTDevice::InUse(int psm)
techand 0:7b556109fd46 260 //{
techand 0:7b556109fd46 261 // for (int i = 0; i < MAX_PORTS; i++){
techand 0:7b556109fd46 262 // printf("Listen Q %d = %d \r\n",i, _listen[i]);
techand 0:7b556109fd46 263 // if ( _listen[i] == psm ) {
techand 0:7b556109fd46 264 // printf("We are listening on port %d \r\n",psm); //in use
techand 0:7b556109fd46 265 // return 0;
techand 0:7b556109fd46 266 // }
techand 0:7b556109fd46 267 // }
techand 0:7b556109fd46 268 // printf("We are not listening on port %d \r\n",psm);
techand 0:7b556109fd46 269 // return 1;
techand 0:7b556109fd46 270 //}
techand 0:7b556109fd46 271
techand 0:7b556109fd46 272
techand 0:7b556109fd46 273
techand 0:7b556109fd46 274
techand 0:7b556109fd46 275 void BTDevice::Control(const BD_ADDR* addr, const u8* data, int len)
techand 0:7b556109fd46 276 {
techand 0:7b556109fd46 277
techand 0:7b556109fd46 278 SocketInternal* sock;
techand 0:7b556109fd46 279 L2CAPSocket* s;
techand 0:7b556109fd46 280 int psm,scid,dcid,flags;
techand 0:7b556109fd46 281
techand 0:7b556109fd46 282 printf("From address ");
techand 0:7b556109fd46 283 printf(addr);
techand 0:7b556109fd46 284 printf(" : ");
techand 0:7b556109fd46 285
techand 0:7b556109fd46 286 int cc = data[8];
techand 0:7b556109fd46 287 printf(L2CAP_ComandCodeStr(cc));
techand 0:7b556109fd46 288 int result = LE16(data+16);
techand 0:7b556109fd46 289 printf(" Result %d\r\n",result);
techand 0:7b556109fd46 290
techand 0:7b556109fd46 291
techand 0:7b556109fd46 292 switch (cc)
techand 0:7b556109fd46 293 {
techand 0:7b556109fd46 294 case L2CAP_COMMAND_REJ:
techand 0:7b556109fd46 295 break;
techand 0:7b556109fd46 296 case L2CAP_CONN_REQ:
techand 0:7b556109fd46 297 {
techand 0:7b556109fd46 298 psm = LE16(data+12);
techand 0:7b556109fd46 299 scid = LE16(data+14);
techand 0:7b556109fd46 300 printf("Connection request scid = %d psm = %d \r\n",scid,psm);
techand 0:7b556109fd46 301
techand 0:7b556109fd46 302 // check if we listen on the port
techand 0:7b556109fd46 303 //if ( InUse(psm) ) {
techand 0:7b556109fd46 304 if ( Socket_InUse(SOCKET_L2CAP,psm) ) {
techand 0:7b556109fd46 305 RefuseResponse(data[9]);
techand 0:7b556109fd46 306
techand 0:7b556109fd46 307
techand 0:7b556109fd46 308 } else {
techand 0:7b556109fd46 309 L2CAPAddr sockAddr;
techand 0:7b556109fd46 310 sockAddr.bdaddr = *addr;
techand 0:7b556109fd46 311 sock = Socket_Create(SOCKET_L2CAP, &sockAddr.hdr, psm);
techand 0:7b556109fd46 312 s = (L2CAPSocket*)sock;
techand 0:7b556109fd46 313 s->scid = 0x40 + sock->ID-1; // are these reserved?
techand 0:7b556109fd46 314 s->dcid = scid;
techand 0:7b556109fd46 315 AcceptResponse(data[9],s->scid,s->dcid);
techand 0:7b556109fd46 316
techand 0:7b556109fd46 317 ConfigureRequest(s->dcid); // handshake
techand 0:7b556109fd46 318
techand 0:7b556109fd46 319 sock->SetState(SocketState_Accept);
techand 0:7b556109fd46 320 }
techand 0:7b556109fd46 321
techand 0:7b556109fd46 322 /**
techand 0:7b556109fd46 323 for (int i = 0; i < MAX_PORTS; i++){
techand 0:7b556109fd46 324 if ( _listen[i] == psm ) {
techand 0:7b556109fd46 325 printf("We are listening on port %d \r\n",psm); //in use
techand 0:7b556109fd46 326 RefuseResponse(data[9]);
techand 0:7b556109fd46 327 break;
techand 0:7b556109fd46 328 }
techand 0:7b556109fd46 329 }
techand 0:7b556109fd46 330 **/
techand 0:7b556109fd46 331
techand 0:7b556109fd46 332 //L2CAPAddr sockAddr;
techand 0:7b556109fd46 333 //sockAddr.bdaddr = addr;
techand 0:7b556109fd46 334 //sockAddr.psm = psm;
techand 0:7b556109fd46 335
techand 0:7b556109fd46 336 }
techand 0:7b556109fd46 337 break;
techand 0:7b556109fd46 338
techand 0:7b556109fd46 339 // Response to our initial connect from Remote
techand 0:7b556109fd46 340 case L2CAP_CONN_RSP:
techand 0:7b556109fd46 341 {
techand 0:7b556109fd46 342 if (result == 0)
techand 0:7b556109fd46 343 {
techand 0:7b556109fd46 344 printf("Connect succeeded\r\n");
techand 0:7b556109fd46 345 dcid = LE16(data+12);
techand 0:7b556109fd46 346 scid = LE16(data+14);
techand 0:7b556109fd46 347 L2CAPSocket* s = SCIDToSocket(scid);
techand 0:7b556109fd46 348 if (s)
techand 0:7b556109fd46 349 {
techand 0:7b556109fd46 350 s->dcid = dcid;
techand 0:7b556109fd46 351 ConfigureRequest(dcid);
techand 0:7b556109fd46 352 }
techand 0:7b556109fd46 353 } else
techand 0:7b556109fd46 354 printf("Connect failed?\r\n");
techand 0:7b556109fd46 355 }
techand 0:7b556109fd46 356 break;
techand 0:7b556109fd46 357
techand 0:7b556109fd46 358 case L2CAP_CONF_RSP:
techand 0:7b556109fd46 359 {
techand 0:7b556109fd46 360 scid = LE16(data+12);
techand 0:7b556109fd46 361 SocketInternal* s = (SocketInternal*)SCIDToSocket(scid);
techand 0:7b556109fd46 362 if (s)
techand 0:7b556109fd46 363 s->SetState(SocketState_Open);
techand 0:7b556109fd46 364 }
techand 0:7b556109fd46 365 break;
techand 0:7b556109fd46 366
techand 0:7b556109fd46 367 case L2CAP_CONF_REQ:
techand 0:7b556109fd46 368 {
techand 0:7b556109fd46 369 u16 dcid = LE16(data+12);
techand 0:7b556109fd46 370 u16 flags = LE16(data+14);
techand 0:7b556109fd46 371 printf("Config request dcid = %02X flags = %02X\r\n", dcid, flags);
techand 0:7b556109fd46 372 scid = LE16(data+12);
techand 0:7b556109fd46 373 L2CAPSocket* s = SCIDToSocket(scid);
techand 0:7b556109fd46 374 if (s)
techand 0:7b556109fd46 375 ConfigureResponse(data[9],s->dcid);
techand 0:7b556109fd46 376 }
techand 0:7b556109fd46 377 break;
techand 0:7b556109fd46 378 case L2CAP_DISCONN_REQ: {
techand 0:7b556109fd46 379 int dcid = LE16(data+12);
techand 0:7b556109fd46 380 int scid = LE16(data+14);
techand 0:7b556109fd46 381 L2CAPSocket* s = SCIDToSocket(scid);
techand 0:7b556109fd46 382 //s->si.SetState(SocketState_Closed);
techand 0:7b556109fd46 383 DisconnectResponse(data[9], scid, dcid);
techand 0:7b556109fd46 384 }
techand 0:7b556109fd46 385 break;
techand 0:7b556109fd46 386
techand 0:7b556109fd46 387 }
techand 0:7b556109fd46 388 }
techand 0:7b556109fd46 389
techand 0:7b556109fd46 390 void BTDevice::ACLRecv(const BD_ADDR* addr, const u8* data, int len)
techand 0:7b556109fd46 391 {
techand 0:7b556109fd46 392 //printfBytes("L2CP recv: ",data,16);
techand 0:7b556109fd46 393 int handle = LE16(data);
techand 0:7b556109fd46 394 if (handle != (0x2000 | _handle))
techand 0:7b556109fd46 395 return;
techand 0:7b556109fd46 396
techand 0:7b556109fd46 397 int cid = LE16(data+6);
techand 0:7b556109fd46 398 if (cid == 1)
techand 0:7b556109fd46 399 {
techand 0:7b556109fd46 400 Control(addr,data,len);
techand 0:7b556109fd46 401 return;
techand 0:7b556109fd46 402 }
techand 0:7b556109fd46 403
techand 0:7b556109fd46 404 SocketInternal* s = (SocketInternal*)SCIDToSocket(cid);
techand 0:7b556109fd46 405 if (s)
techand 0:7b556109fd46 406 s->Recv(data+8,LE16(data+2)-4);
techand 0:7b556109fd46 407 else
techand 0:7b556109fd46 408 printf("Bad event cid %d\r\n",cid);
techand 0:7b556109fd46 409 }