![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Code to control a Traxster robot using a Wimote and Android app
Fork of BlueUSB by
BlueUSB/L2CAP.cpp@1:accdaa84fe8d, 2014-04-28 (annotated)
- Committer:
- aswild
- Date:
- Mon Apr 28 16:06:32 2014 +0000
- Revision:
- 1:accdaa84fe8d
- Parent:
- L2CAP.cpp@0:606b230e5b4a
Wiimote controlled Traxster robot using BlueUSB
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
peterbarrett1967 | 0:606b230e5b4a | 1 | /* |
peterbarrett1967 | 0:606b230e5b4a | 2 | Copyright (c) 2010 Peter Barrett |
peterbarrett1967 | 0:606b230e5b4a | 3 | |
peterbarrett1967 | 0:606b230e5b4a | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy |
peterbarrett1967 | 0:606b230e5b4a | 5 | of this software and associated documentation files (the "Software"), to deal |
peterbarrett1967 | 0:606b230e5b4a | 6 | in the Software without restriction, including without limitation the rights |
peterbarrett1967 | 0:606b230e5b4a | 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
peterbarrett1967 | 0:606b230e5b4a | 8 | copies of the Software, and to permit persons to whom the Software is |
peterbarrett1967 | 0:606b230e5b4a | 9 | furnished to do so, subject to the following conditions: |
peterbarrett1967 | 0:606b230e5b4a | 10 | |
peterbarrett1967 | 0:606b230e5b4a | 11 | The above copyright notice and this permission notice shall be included in |
peterbarrett1967 | 0:606b230e5b4a | 12 | all copies or substantial portions of the Software. |
peterbarrett1967 | 0:606b230e5b4a | 13 | |
peterbarrett1967 | 0:606b230e5b4a | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
peterbarrett1967 | 0:606b230e5b4a | 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
peterbarrett1967 | 0:606b230e5b4a | 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
peterbarrett1967 | 0:606b230e5b4a | 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
peterbarrett1967 | 0:606b230e5b4a | 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
peterbarrett1967 | 0:606b230e5b4a | 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
peterbarrett1967 | 0:606b230e5b4a | 20 | THE SOFTWARE. |
peterbarrett1967 | 0:606b230e5b4a | 21 | */ |
peterbarrett1967 | 0:606b230e5b4a | 22 | |
peterbarrett1967 | 0:606b230e5b4a | 23 | |
peterbarrett1967 | 0:606b230e5b4a | 24 | #include <stdio.h> |
peterbarrett1967 | 0:606b230e5b4a | 25 | #include <stdlib.h> |
peterbarrett1967 | 0:606b230e5b4a | 26 | #include <stdio.h> |
peterbarrett1967 | 0:606b230e5b4a | 27 | #include <string.h> |
peterbarrett1967 | 0:606b230e5b4a | 28 | |
peterbarrett1967 | 0:606b230e5b4a | 29 | #include "Utils.h" |
peterbarrett1967 | 0:606b230e5b4a | 30 | #include "hci.h" |
peterbarrett1967 | 0:606b230e5b4a | 31 | |
peterbarrett1967 | 0:606b230e5b4a | 32 | #define L2CAP_COMMAND_REJ 0x01 |
peterbarrett1967 | 0:606b230e5b4a | 33 | #define L2CAP_CONN_REQ 0x02 |
peterbarrett1967 | 0:606b230e5b4a | 34 | #define L2CAP_CONN_RSP 0x03 |
peterbarrett1967 | 0:606b230e5b4a | 35 | #define L2CAP_CONF_REQ 0x04 |
peterbarrett1967 | 0:606b230e5b4a | 36 | #define L2CAP_CONF_RSP 0x05 |
peterbarrett1967 | 0:606b230e5b4a | 37 | #define L2CAP_DISCONN_REQ 0x06 |
peterbarrett1967 | 0:606b230e5b4a | 38 | #define L2CAP_DISCONN_RSP 0x07 |
peterbarrett1967 | 0:606b230e5b4a | 39 | #define L2CAP_ECHO_REQ 0x08 |
peterbarrett1967 | 0:606b230e5b4a | 40 | #define L2CAP_ECHO_RSP 0x09 |
peterbarrett1967 | 0:606b230e5b4a | 41 | #define L2CAP_INFO_REQ 0x0a |
peterbarrett1967 | 0:606b230e5b4a | 42 | #define L2CAP_INFO_RSP 0x0b |
peterbarrett1967 | 0:606b230e5b4a | 43 | |
peterbarrett1967 | 0:606b230e5b4a | 44 | |
peterbarrett1967 | 0:606b230e5b4a | 45 | /* L2CAP command codes */ |
peterbarrett1967 | 0:606b230e5b4a | 46 | const char* L2CAP_ComandCodeStr(int c) |
peterbarrett1967 | 0:606b230e5b4a | 47 | { |
peterbarrett1967 | 0:606b230e5b4a | 48 | switch (c) |
peterbarrett1967 | 0:606b230e5b4a | 49 | { |
peterbarrett1967 | 0:606b230e5b4a | 50 | case L2CAP_COMMAND_REJ: return "L2CAP_COMMAND_REJ"; |
peterbarrett1967 | 0:606b230e5b4a | 51 | case L2CAP_CONN_REQ: return "L2CAP_CONN_REQ"; |
peterbarrett1967 | 0:606b230e5b4a | 52 | case L2CAP_CONN_RSP: return "L2CAP_CONN_RSP"; |
peterbarrett1967 | 0:606b230e5b4a | 53 | case L2CAP_CONF_REQ: return "L2CAP_CONF_REQ"; |
peterbarrett1967 | 0:606b230e5b4a | 54 | case L2CAP_CONF_RSP: return "L2CAP_CONF_RSP"; |
peterbarrett1967 | 0:606b230e5b4a | 55 | case L2CAP_DISCONN_REQ: return "L2CAP_DISCONN_REQ"; |
peterbarrett1967 | 0:606b230e5b4a | 56 | case L2CAP_DISCONN_RSP: return "L2CAP_DISCONN_RSP"; |
peterbarrett1967 | 0:606b230e5b4a | 57 | case L2CAP_ECHO_REQ: return "L2CAP_ECHO_REQ"; |
peterbarrett1967 | 0:606b230e5b4a | 58 | case L2CAP_ECHO_RSP: return "L2CAP_ECHO_RSP"; |
peterbarrett1967 | 0:606b230e5b4a | 59 | case L2CAP_INFO_REQ: return "L2CAP_INFO_REQ"; |
peterbarrett1967 | 0:606b230e5b4a | 60 | case L2CAP_INFO_RSP: return "L2CAP_INFO_RSP"; |
peterbarrett1967 | 0:606b230e5b4a | 61 | } |
peterbarrett1967 | 0:606b230e5b4a | 62 | return "unknown"; |
peterbarrett1967 | 0:606b230e5b4a | 63 | } |
peterbarrett1967 | 0:606b230e5b4a | 64 | |
peterbarrett1967 | 0:606b230e5b4a | 65 | typedef struct |
peterbarrett1967 | 0:606b230e5b4a | 66 | { |
peterbarrett1967 | 0:606b230e5b4a | 67 | u16 handle; |
peterbarrett1967 | 0:606b230e5b4a | 68 | u16 length; // total |
peterbarrett1967 | 0:606b230e5b4a | 69 | u16 l2capLength; // length -4 |
peterbarrett1967 | 0:606b230e5b4a | 70 | u16 cid; // Signaling packet CID = 1 |
peterbarrett1967 | 0:606b230e5b4a | 71 | u8 data[64]; // Largest thing to send!!! todo |
peterbarrett1967 | 0:606b230e5b4a | 72 | } L2CAPData; |
peterbarrett1967 | 0:606b230e5b4a | 73 | |
peterbarrett1967 | 0:606b230e5b4a | 74 | typedef struct |
peterbarrett1967 | 0:606b230e5b4a | 75 | { |
peterbarrett1967 | 0:606b230e5b4a | 76 | u16 handle; |
peterbarrett1967 | 0:606b230e5b4a | 77 | u16 length; // total |
peterbarrett1967 | 0:606b230e5b4a | 78 | u16 l2capLength; // length -4 |
peterbarrett1967 | 0:606b230e5b4a | 79 | u16 cid; // Signaling packet CID = 1 |
peterbarrett1967 | 0:606b230e5b4a | 80 | |
peterbarrett1967 | 0:606b230e5b4a | 81 | // Payload |
peterbarrett1967 | 0:606b230e5b4a | 82 | u8 cmd; // |
peterbarrett1967 | 0:606b230e5b4a | 83 | u8 id; |
peterbarrett1967 | 0:606b230e5b4a | 84 | u16 cmdLength; // total-8 |
peterbarrett1967 | 0:606b230e5b4a | 85 | u16 params[4]; // Params |
peterbarrett1967 | 0:606b230e5b4a | 86 | } L2CAPCmd; |
peterbarrett1967 | 0:606b230e5b4a | 87 | |
peterbarrett1967 | 0:606b230e5b4a | 88 | // |
peterbarrett1967 | 0:606b230e5b4a | 89 | void BTDevice::Init() |
peterbarrett1967 | 0:606b230e5b4a | 90 | { |
peterbarrett1967 | 0:606b230e5b4a | 91 | memset(&_info,0,sizeof(inquiry_info)); |
peterbarrett1967 | 0:606b230e5b4a | 92 | _handle = 0; |
peterbarrett1967 | 0:606b230e5b4a | 93 | _name[0] = 0; |
peterbarrett1967 | 0:606b230e5b4a | 94 | _state = 0; |
peterbarrett1967 | 0:606b230e5b4a | 95 | } |
peterbarrett1967 | 0:606b230e5b4a | 96 | |
peterbarrett1967 | 0:606b230e5b4a | 97 | // virtual SocketHandler |
peterbarrett1967 | 0:606b230e5b4a | 98 | int BTDevice::Open(SocketInternal* sock, SocketAddrHdr* addr) |
peterbarrett1967 | 0:606b230e5b4a | 99 | { |
peterbarrett1967 | 0:606b230e5b4a | 100 | L2CAPSocket* s = (L2CAPSocket*)sock; |
peterbarrett1967 | 0:606b230e5b4a | 101 | L2CAPAddr* a = (L2CAPAddr*)addr; |
peterbarrett1967 | 0:606b230e5b4a | 102 | s->scid = 0x40 + sock->ID-1; // are these reserved? |
peterbarrett1967 | 0:606b230e5b4a | 103 | s->dcid = 0; |
peterbarrett1967 | 0:606b230e5b4a | 104 | Connect(s->scid,a->psm); |
peterbarrett1967 | 0:606b230e5b4a | 105 | return sock->ID; |
peterbarrett1967 | 0:606b230e5b4a | 106 | } |
peterbarrett1967 | 0:606b230e5b4a | 107 | |
peterbarrett1967 | 0:606b230e5b4a | 108 | // virtual SocketHandler |
peterbarrett1967 | 0:606b230e5b4a | 109 | int BTDevice::Send(SocketInternal* sock, const u8* data, int len) |
peterbarrett1967 | 0:606b230e5b4a | 110 | { |
peterbarrett1967 | 0:606b230e5b4a | 111 | L2CAPData d; |
peterbarrett1967 | 0:606b230e5b4a | 112 | L2CAPSocket* s = (L2CAPSocket*)sock; |
peterbarrett1967 | 0:606b230e5b4a | 113 | |
peterbarrett1967 | 0:606b230e5b4a | 114 | d.handle = _handle | 0x2000; |
peterbarrett1967 | 0:606b230e5b4a | 115 | d.length = 4 + len; |
peterbarrett1967 | 0:606b230e5b4a | 116 | d.l2capLength = len; |
peterbarrett1967 | 0:606b230e5b4a | 117 | d.cid = s->dcid; |
peterbarrett1967 | 0:606b230e5b4a | 118 | |
peterbarrett1967 | 0:606b230e5b4a | 119 | if (len > 64) |
peterbarrett1967 | 0:606b230e5b4a | 120 | return -1; |
peterbarrett1967 | 0:606b230e5b4a | 121 | memcpy(d.data,data,len); |
peterbarrett1967 | 0:606b230e5b4a | 122 | return Send((u8*)&d,len+8); |
peterbarrett1967 | 0:606b230e5b4a | 123 | } |
peterbarrett1967 | 0:606b230e5b4a | 124 | |
peterbarrett1967 | 0:606b230e5b4a | 125 | // virtual SocketHandler |
peterbarrett1967 | 0:606b230e5b4a | 126 | int BTDevice::Close(SocketInternal* sock) |
peterbarrett1967 | 0:606b230e5b4a | 127 | { |
peterbarrett1967 | 0:606b230e5b4a | 128 | printf("L2CAP close %d\n",sock->ID); |
peterbarrett1967 | 0:606b230e5b4a | 129 | L2CAPSocket* s = (L2CAPSocket*)sock; |
peterbarrett1967 | 0:606b230e5b4a | 130 | return Disconnect(s->scid,s->dcid); |
peterbarrett1967 | 0:606b230e5b4a | 131 | } |
peterbarrett1967 | 0:606b230e5b4a | 132 | |
peterbarrett1967 | 0:606b230e5b4a | 133 | L2CAPSocket* BTDevice::SCIDToSocket(int scid) |
peterbarrett1967 | 0:606b230e5b4a | 134 | { |
peterbarrett1967 | 0:606b230e5b4a | 135 | return (L2CAPSocket*)GetSocketInternal(scid-0x40+1); |
peterbarrett1967 | 0:606b230e5b4a | 136 | } |
peterbarrett1967 | 0:606b230e5b4a | 137 | |
peterbarrett1967 | 0:606b230e5b4a | 138 | int BTDevice::Send(const u8* data, int len) |
peterbarrett1967 | 0:606b230e5b4a | 139 | { |
peterbarrett1967 | 0:606b230e5b4a | 140 | _transport->ACLSend(data,len); |
peterbarrett1967 | 0:606b230e5b4a | 141 | return 0; |
peterbarrett1967 | 0:606b230e5b4a | 142 | } |
peterbarrett1967 | 0:606b230e5b4a | 143 | |
peterbarrett1967 | 0:606b230e5b4a | 144 | int BTDevice::Send(u8 c, u8 id, u16* params, int count) |
peterbarrett1967 | 0:606b230e5b4a | 145 | { |
peterbarrett1967 | 0:606b230e5b4a | 146 | L2CAPCmd cmd; |
peterbarrett1967 | 0:606b230e5b4a | 147 | cmd.handle = _handle | 0x2000; |
peterbarrett1967 | 0:606b230e5b4a | 148 | cmd.length = 8 + count*2; |
peterbarrett1967 | 0:606b230e5b4a | 149 | |
peterbarrett1967 | 0:606b230e5b4a | 150 | cmd.l2capLength = cmd.length-4; |
peterbarrett1967 | 0:606b230e5b4a | 151 | cmd.cid = 1; // Signaling packet |
peterbarrett1967 | 0:606b230e5b4a | 152 | |
peterbarrett1967 | 0:606b230e5b4a | 153 | cmd.cmd = c; |
peterbarrett1967 | 0:606b230e5b4a | 154 | cmd.id = id; |
peterbarrett1967 | 0:606b230e5b4a | 155 | cmd.cmdLength = count*2; |
peterbarrett1967 | 0:606b230e5b4a | 156 | for (int i = 0; i < count; i++) |
peterbarrett1967 | 0:606b230e5b4a | 157 | cmd.params[i] = params[i]; |
peterbarrett1967 | 0:606b230e5b4a | 158 | return Send((u8*)&cmd,cmd.length+4); |
peterbarrett1967 | 0:606b230e5b4a | 159 | } |
peterbarrett1967 | 0:606b230e5b4a | 160 | |
peterbarrett1967 | 0:606b230e5b4a | 161 | int BTDevice::Connect(int scid, int psm) |
peterbarrett1967 | 0:606b230e5b4a | 162 | { |
peterbarrett1967 | 0:606b230e5b4a | 163 | u16 p[2]; |
peterbarrett1967 | 0:606b230e5b4a | 164 | p[0] = psm; |
peterbarrett1967 | 0:606b230e5b4a | 165 | p[1] = scid; |
peterbarrett1967 | 0:606b230e5b4a | 166 | return Send(L2CAP_CONN_REQ,_txid++,p,2); |
peterbarrett1967 | 0:606b230e5b4a | 167 | } |
peterbarrett1967 | 0:606b230e5b4a | 168 | |
peterbarrett1967 | 0:606b230e5b4a | 169 | int BTDevice::Disconnect(int scid, int dcid) |
peterbarrett1967 | 0:606b230e5b4a | 170 | { |
peterbarrett1967 | 0:606b230e5b4a | 171 | u16 p[2]; |
peterbarrett1967 | 0:606b230e5b4a | 172 | p[0] = dcid; |
peterbarrett1967 | 0:606b230e5b4a | 173 | p[1] = scid; |
peterbarrett1967 | 0:606b230e5b4a | 174 | return Send(L2CAP_DISCONN_REQ,_txid++,p,2); |
peterbarrett1967 | 0:606b230e5b4a | 175 | } |
peterbarrett1967 | 0:606b230e5b4a | 176 | |
peterbarrett1967 | 0:606b230e5b4a | 177 | int BTDevice::ConfigureRequest(int dcid) |
peterbarrett1967 | 0:606b230e5b4a | 178 | { |
peterbarrett1967 | 0:606b230e5b4a | 179 | u16 p[4]; |
peterbarrett1967 | 0:606b230e5b4a | 180 | p[0] = dcid; |
peterbarrett1967 | 0:606b230e5b4a | 181 | p[1] = 0; |
peterbarrett1967 | 0:606b230e5b4a | 182 | p[2] = 0x0201; // Options |
peterbarrett1967 | 0:606b230e5b4a | 183 | p[3] = 0x02A0; // 672 |
peterbarrett1967 | 0:606b230e5b4a | 184 | return Send(L2CAP_CONF_REQ,_txid++,p,4); |
peterbarrett1967 | 0:606b230e5b4a | 185 | } |
peterbarrett1967 | 0:606b230e5b4a | 186 | |
peterbarrett1967 | 0:606b230e5b4a | 187 | int BTDevice::ConfigureResponse(u8 rxid, int dcid) |
peterbarrett1967 | 0:606b230e5b4a | 188 | { |
peterbarrett1967 | 0:606b230e5b4a | 189 | u16 p[3]; |
peterbarrett1967 | 0:606b230e5b4a | 190 | p[0] = dcid; |
peterbarrett1967 | 0:606b230e5b4a | 191 | p[1] = 0; |
peterbarrett1967 | 0:606b230e5b4a | 192 | p[2] = 0; |
peterbarrett1967 | 0:606b230e5b4a | 193 | return Send(L2CAP_CONF_RSP,rxid,p,3); |
peterbarrett1967 | 0:606b230e5b4a | 194 | } |
peterbarrett1967 | 0:606b230e5b4a | 195 | |
peterbarrett1967 | 0:606b230e5b4a | 196 | int BTDevice::DisconnectResponse(u8 rxid, int scid, int dcid) |
peterbarrett1967 | 0:606b230e5b4a | 197 | { |
peterbarrett1967 | 0:606b230e5b4a | 198 | u16 p[2]; |
peterbarrett1967 | 0:606b230e5b4a | 199 | p[0] = dcid; |
peterbarrett1967 | 0:606b230e5b4a | 200 | p[1] = scid; |
peterbarrett1967 | 0:606b230e5b4a | 201 | return Send(L2CAP_DISCONN_RSP,rxid,p,2); |
peterbarrett1967 | 0:606b230e5b4a | 202 | } |
peterbarrett1967 | 0:606b230e5b4a | 203 | |
peterbarrett1967 | 0:606b230e5b4a | 204 | void BTDevice::Control(const u8* data, int len) |
peterbarrett1967 | 0:606b230e5b4a | 205 | { |
peterbarrett1967 | 0:606b230e5b4a | 206 | int cc = data[8]; |
peterbarrett1967 | 0:606b230e5b4a | 207 | printf(L2CAP_ComandCodeStr(cc)); |
peterbarrett1967 | 0:606b230e5b4a | 208 | int result = LE16(data+16); |
peterbarrett1967 | 0:606b230e5b4a | 209 | printf(" Result %d\n",result); |
peterbarrett1967 | 0:606b230e5b4a | 210 | switch (cc) |
peterbarrett1967 | 0:606b230e5b4a | 211 | { |
peterbarrett1967 | 0:606b230e5b4a | 212 | case L2CAP_COMMAND_REJ: |
peterbarrett1967 | 0:606b230e5b4a | 213 | break; |
peterbarrett1967 | 0:606b230e5b4a | 214 | case L2CAP_CONN_REQ: |
peterbarrett1967 | 0:606b230e5b4a | 215 | break; |
peterbarrett1967 | 0:606b230e5b4a | 216 | |
peterbarrett1967 | 0:606b230e5b4a | 217 | // Response to our initial connect from Remote |
peterbarrett1967 | 0:606b230e5b4a | 218 | case L2CAP_CONN_RSP: |
peterbarrett1967 | 0:606b230e5b4a | 219 | { |
peterbarrett1967 | 0:606b230e5b4a | 220 | if (result == 0) |
peterbarrett1967 | 0:606b230e5b4a | 221 | { |
peterbarrett1967 | 0:606b230e5b4a | 222 | int dcid = LE16(data+12); |
peterbarrett1967 | 0:606b230e5b4a | 223 | int scid = LE16(data+14); |
peterbarrett1967 | 0:606b230e5b4a | 224 | L2CAPSocket* s = SCIDToSocket(scid); |
peterbarrett1967 | 0:606b230e5b4a | 225 | if (s) |
peterbarrett1967 | 0:606b230e5b4a | 226 | { |
peterbarrett1967 | 0:606b230e5b4a | 227 | s->dcid = dcid; |
peterbarrett1967 | 0:606b230e5b4a | 228 | ConfigureRequest(dcid); |
peterbarrett1967 | 0:606b230e5b4a | 229 | } |
peterbarrett1967 | 0:606b230e5b4a | 230 | } else |
peterbarrett1967 | 0:606b230e5b4a | 231 | printf("Connect failed?\n"); |
peterbarrett1967 | 0:606b230e5b4a | 232 | } |
peterbarrett1967 | 0:606b230e5b4a | 233 | break; |
peterbarrett1967 | 0:606b230e5b4a | 234 | |
peterbarrett1967 | 0:606b230e5b4a | 235 | case L2CAP_CONF_RSP: |
peterbarrett1967 | 0:606b230e5b4a | 236 | { |
peterbarrett1967 | 0:606b230e5b4a | 237 | int scid = LE16(data+12); |
peterbarrett1967 | 0:606b230e5b4a | 238 | SocketInternal* s = (SocketInternal*)SCIDToSocket(scid); |
peterbarrett1967 | 0:606b230e5b4a | 239 | if (s) |
peterbarrett1967 | 0:606b230e5b4a | 240 | s->SetState(SocketState_Open); |
peterbarrett1967 | 0:606b230e5b4a | 241 | } |
peterbarrett1967 | 0:606b230e5b4a | 242 | break; |
peterbarrett1967 | 0:606b230e5b4a | 243 | |
peterbarrett1967 | 0:606b230e5b4a | 244 | case L2CAP_CONF_REQ: |
peterbarrett1967 | 0:606b230e5b4a | 245 | { |
peterbarrett1967 | 0:606b230e5b4a | 246 | int scid = LE16(data+12); |
peterbarrett1967 | 0:606b230e5b4a | 247 | L2CAPSocket* s = SCIDToSocket(scid); |
peterbarrett1967 | 0:606b230e5b4a | 248 | if (s) |
peterbarrett1967 | 0:606b230e5b4a | 249 | ConfigureResponse(data[9],s->dcid); |
peterbarrett1967 | 0:606b230e5b4a | 250 | } |
peterbarrett1967 | 0:606b230e5b4a | 251 | break; |
peterbarrett1967 | 0:606b230e5b4a | 252 | } |
peterbarrett1967 | 0:606b230e5b4a | 253 | } |
peterbarrett1967 | 0:606b230e5b4a | 254 | |
peterbarrett1967 | 0:606b230e5b4a | 255 | void BTDevice::ACLRecv(const u8* data, int len) |
peterbarrett1967 | 0:606b230e5b4a | 256 | { |
peterbarrett1967 | 0:606b230e5b4a | 257 | // printfBytes("L2CP",data,16); |
peterbarrett1967 | 0:606b230e5b4a | 258 | int handle = LE16(data); |
peterbarrett1967 | 0:606b230e5b4a | 259 | if (handle != (0x2000 | _handle)) |
peterbarrett1967 | 0:606b230e5b4a | 260 | return; |
peterbarrett1967 | 0:606b230e5b4a | 261 | |
peterbarrett1967 | 0:606b230e5b4a | 262 | int cid = LE16(data+6); |
peterbarrett1967 | 0:606b230e5b4a | 263 | if (cid == 1) |
peterbarrett1967 | 0:606b230e5b4a | 264 | { |
peterbarrett1967 | 0:606b230e5b4a | 265 | Control(data,len); |
peterbarrett1967 | 0:606b230e5b4a | 266 | return; |
peterbarrett1967 | 0:606b230e5b4a | 267 | } |
peterbarrett1967 | 0:606b230e5b4a | 268 | |
peterbarrett1967 | 0:606b230e5b4a | 269 | SocketInternal* s = (SocketInternal*)SCIDToSocket(cid); |
peterbarrett1967 | 0:606b230e5b4a | 270 | if (s) |
peterbarrett1967 | 0:606b230e5b4a | 271 | s->Recv(data+8,LE16(data+2)-4); |
peterbarrett1967 | 0:606b230e5b4a | 272 | else |
peterbarrett1967 | 0:606b230e5b4a | 273 | printf("Bad event cid %d\n",cid); |
peterbarrett1967 | 0:606b230e5b4a | 274 | } |