mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-03-23 19:20:51 +00:00
dispatch l2cap commands
This commit is contained in:
parent
12cace437d
commit
1f7b95a184
2
TODO.txt
2
TODO.txt
@ -9,7 +9,7 @@ NEXT:
|
||||
- new commands
|
||||
- l2cap_register_service(psm, mtu)
|
||||
- l2cap_unregister_service(psm)
|
||||
- l2cap_accept_connection( bd_addr_t, dest cid )
|
||||
- l2cap_accept_connection_internal( bd_addr_t, dest cid )
|
||||
- l2cap_deny_connection( bd_addr_t, dest cid, reason )
|
||||
- events
|
||||
- l2cap_incoming_connection(psm, handle, dest cid)
|
||||
|
@ -115,8 +115,12 @@
|
||||
// data: event (8), len(8), channel (16)
|
||||
#define L2CAP_EVENT_CHANNEL_CLOSED 0x71
|
||||
|
||||
// data: event(8), len(8), address(48), handle (16), psm (16), dest cid(16)
|
||||
#define L2CAP_EVENT_INCOMING_CONNECTION 0x72
|
||||
|
||||
// data: event(8), len(8), handle(16)
|
||||
#define L2CAP_EVENT_TIMEOUT_CHECK 0x72
|
||||
#define L2CAP_EVENT_TIMEOUT_CHECK 0x73
|
||||
|
||||
|
||||
// last HCI error is 0x3d
|
||||
// l2cap errors - enumeration by the command that created them
|
||||
@ -205,5 +209,9 @@ extern hci_cmd_t hci_write_page_timeout;
|
||||
extern hci_cmd_t hci_write_scan_enable;
|
||||
extern hci_cmd_t hci_write_simple_pairing_mode;
|
||||
|
||||
extern hci_cmd_t l2cap_accept_connection;
|
||||
extern hci_cmd_t l2cap_create_channel;
|
||||
extern hci_cmd_t l2cap_decline_connection;
|
||||
extern hci_cmd_t l2cap_disconnect;
|
||||
extern hci_cmd_t l2cap_register_service;
|
||||
extern hci_cmd_t l2cap_unregister_service;
|
||||
|
@ -68,6 +68,7 @@
|
||||
9C46FC370FA906F700ABEF05 /* hci_transport_h4.h */ = {isa = PBXFileReference; fileEncoding = 5; lastKnownFileType = sourcecode.c.h; name = hci_transport_h4.h; path = src/hci_transport_h4.h; sourceTree = "<group>"; };
|
||||
9C46FC380FA906F700ABEF05 /* hci_transport.h */ = {isa = PBXFileReference; fileEncoding = 5; lastKnownFileType = sourcecode.c.h; name = hci_transport.h; path = src/hci_transport.h; sourceTree = "<group>"; };
|
||||
9C5BA8A0110B756500D79BBE /* hci_cmds.h */ = {isa = PBXFileReference; fileEncoding = 5; lastKnownFileType = sourcecode.c.h; name = hci_cmds.h; path = include/btstack/hci_cmds.h; sourceTree = "<group>"; };
|
||||
9C5BABAF110E28E900D79BBE /* l2cap-server.c */ = {isa = PBXFileReference; fileEncoding = 5; lastKnownFileType = sourcecode.c.c; name = "l2cap-server.c"; path = "example/l2cap-server.c"; sourceTree = "<group>"; };
|
||||
9C6459DE1037554B0081A00B /* platform_iphone.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = platform_iphone.h; path = src/platform_iphone.h; sourceTree = "<group>"; };
|
||||
9C77E36410618B1D00F39DCF /* Makefile.in */ = {isa = PBXFileReference; fileEncoding = 5; lastKnownFileType = text; name = Makefile.in; path = SpringBoardAccess/Makefile.in; sourceTree = "<group>"; };
|
||||
9C77E36710618C6500F39DCF /* SpringBoardAccess-test.c */ = {isa = PBXFileReference; fileEncoding = 5; lastKnownFileType = sourcecode.c.c; name = "SpringBoardAccess-test.c"; path = "SpringBoardAccess/SpringBoardAccess-test.c"; sourceTree = "<group>"; };
|
||||
@ -249,6 +250,7 @@
|
||||
9C7B5B81100D04520065D87E /* Example */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
9C5BABAF110E28E900D79BBE /* l2cap-server.c */,
|
||||
9CAA573610A5D87400D0E1A9 /* inquiry.c */,
|
||||
9C13C9F610ECECE900B04243 /* mouse.c */,
|
||||
9C994B8E106BEEB700C70311 /* rfcomm.c */,
|
||||
|
24
src/daemon.c
24
src/daemon.c
@ -99,7 +99,9 @@ static int btstack_command_handler(connection_t *connection, uint8_t *packet, ui
|
||||
bd_addr_t addr;
|
||||
uint16_t cid;
|
||||
uint16_t psm;
|
||||
uint8_t reason;
|
||||
uint16_t mtu;
|
||||
uint16_t handle;
|
||||
uint8_t reason;
|
||||
// BTstack internal commands - 16 Bit OpCode, 8 Bit ParamLen, Params...
|
||||
switch (READ_CMD_OCF(packet)){
|
||||
case BTSTACK_GET_STATE:
|
||||
@ -141,6 +143,26 @@ static int btstack_command_handler(connection_t *connection, uint8_t *packet, ui
|
||||
reason = packet[5];
|
||||
l2cap_disconnect_internal(cid, reason);
|
||||
break;
|
||||
case L2CAP_REGISTER_SERVICE:
|
||||
psm = READ_BT_16(packet, 3);
|
||||
mtu = READ_BT_16(packet, 5);
|
||||
l2cap_register_service_internal(connection, psm, mtu);
|
||||
break;
|
||||
case L2CAP_UNREGISTER_SERVICE:
|
||||
psm = READ_BT_16(packet, 3);
|
||||
l2cap_unregister_service_internal(connection, psm);
|
||||
break;
|
||||
case L2CAP_ACCEPT_CONNECTION:
|
||||
handle = READ_BT_16(packet, 3);
|
||||
cid = READ_BT_16(packet, 5);
|
||||
l2cap_accept_connection_internal(handle, cid);
|
||||
break;
|
||||
case L2CAP_DECLINE_CONNECTION:
|
||||
handle = READ_BT_16(packet, 3);
|
||||
cid = READ_BT_16(packet, 5);
|
||||
reason = packet[7];
|
||||
l2cap_decline_connection_internal(handle, cid, reason);
|
||||
break;
|
||||
default:
|
||||
//@TODO: log into hci dump as vendor specific "event"
|
||||
fprintf(stderr, "Error: command %u not implemented\n:", READ_CMD_OCF(packet));
|
||||
|
15
src/hci.c
15
src/hci.c
@ -177,6 +177,7 @@ static void acl_handler(uint8_t *packet, int size){
|
||||
static void event_handler(uint8_t *packet, int size){
|
||||
bd_addr_t addr;
|
||||
hci_con_handle_t handle;
|
||||
hci_connection_t * conn;
|
||||
|
||||
switch (packet[0]) {
|
||||
|
||||
@ -186,11 +187,23 @@ static void event_handler(uint8_t *packet, int size){
|
||||
hci_stack.num_cmd_packets = packet[2];
|
||||
break;
|
||||
|
||||
case HCI_EVENT_CONNECTION_REQUEST:
|
||||
bt_flip_addr(addr, &packet[5]);
|
||||
printf("Connection_incoming: "); print_bd_addr(addr); printf("\n");
|
||||
conn = connection_for_address(addr);
|
||||
if (!conn) {
|
||||
conn = create_connection_for_addr(addr);
|
||||
}
|
||||
// TODO: check for malloc failure
|
||||
conn->state = ACCEPTED_CONNECTION_REQUEST;
|
||||
hci_send_cmd(&hci_accept_connection_request, 1);
|
||||
break;
|
||||
|
||||
case HCI_EVENT_CONNECTION_COMPLETE:
|
||||
// Connection management
|
||||
bt_flip_addr(addr, &packet[5]);
|
||||
printf("Connection_complete (status=%u)", packet[2]); print_bd_addr(addr); printf("\n");
|
||||
hci_connection_t * conn = connection_for_address(addr);
|
||||
conn = connection_for_address(addr);
|
||||
if (conn) {
|
||||
if (!packet[2]){
|
||||
conn->state = OPEN;
|
||||
|
@ -320,12 +320,12 @@ OPCODE(OGF_BTSTACK, L2CAP_UNREGISTER_SERVICE), "2"
|
||||
// @param psm (16)
|
||||
};
|
||||
hci_cmd_t l2cap_accept_connection = {
|
||||
OPCODE(OGF_BTSTACK, L2CAP_ACCEPT_CONNECTION), "B2"
|
||||
// @param bd_addr(48), dest cid (16)
|
||||
OPCODE(OGF_BTSTACK, L2CAP_ACCEPT_CONNECTION), "22"
|
||||
// @param handle(16), dest cid (16)
|
||||
};
|
||||
hci_cmd_t l2cap_decline_connection = {
|
||||
OPCODE(OGF_BTSTACK, L2CAP_DECLINE_CONNECTION), "B2"
|
||||
// @param bd_addr(48), dest cid (16)
|
||||
OPCODE(OGF_BTSTACK, L2CAP_DECLINE_CONNECTION), "221"
|
||||
// @param handle(16), dest cid (16), reason(8)
|
||||
};
|
||||
|
||||
|
||||
|
@ -436,6 +436,14 @@ void l2cap_close_connection(connection_t *connection){
|
||||
|
||||
}
|
||||
|
||||
void l2cap_accept_connection_internal(hci_con_handle_t handle, uint16_t dest_cid){
|
||||
printf("l2cap_accept_connection_internal called but not implemented yet 0x%x, 0x%x\n", handle, dest_cid);
|
||||
}
|
||||
|
||||
void l2cap_decline_connection_internal(hci_con_handle_t handle, uint16_t dest_cid, uint8_t reason){
|
||||
printf("l2cap_decline_connection_internal called but not implemented yet 0x%x, 0x%x, %u", handle, dest_cid,reason);
|
||||
}
|
||||
|
||||
// notify client
|
||||
void l2cap_emit_channel_opened(l2cap_channel_t *channel, uint8_t status) {
|
||||
uint8_t event[17];
|
||||
|
@ -107,8 +107,8 @@ l2cap_service_t * l2cap_get_service(uint16_t psm);
|
||||
void l2cap_register_service_internal(connection_t *connection, uint16_t psm, uint16_t);
|
||||
void l2cap_unregister_service_internal(connection_t *connection, uint16_t psm);
|
||||
|
||||
void l2cap_accept_connection(bd_addr_t address, uint16_t dest_cid);
|
||||
void l2cap_decline_connection(bd_addr_t address, uint16_t dest_cid, uint8_t reason);
|
||||
void l2cap_accept_connection_internal(hci_con_handle_t handle, uint16_t dest_cid);
|
||||
void l2cap_decline_connection_internal(hci_con_handle_t handle, uint16_t dest_cid, uint8_t reason);
|
||||
|
||||
void l2cap_emit_channel_opened(l2cap_channel_t *channel, uint8_t status);
|
||||
void l2cap_emit_channel_closed(l2cap_channel_t *channel);
|
||||
|
Loading…
x
Reference in New Issue
Block a user