mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-01-26 12:35:25 +00:00
use l2cap_register instead of l2cap_register_internal, move service registered event generation to daemon
This commit is contained in:
parent
6551847ef9
commit
be2053a636
@ -602,6 +602,17 @@ static void send_l2cap_connection_open_failed(connection_t * connection, bd_addr
|
|||||||
socket_connection_send_packet(connection, HCI_EVENT_PACKET, 0, event, sizeof(event));
|
socket_connection_send_packet(connection, HCI_EVENT_PACKET, 0, event, sizeof(event));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void l2cap_emit_service_registered(void *connection, uint8_t status, uint16_t psm){
|
||||||
|
log_info("L2CAP_EVENT_SERVICE_REGISTERED status 0x%x psm 0x%x", status, psm);
|
||||||
|
uint8_t event[5];
|
||||||
|
event[0] = L2CAP_EVENT_SERVICE_REGISTERED;
|
||||||
|
event[1] = sizeof(event) - 2;
|
||||||
|
event[2] = status;
|
||||||
|
bt_store_16(event, 3, psm);
|
||||||
|
hci_dump_packet( HCI_EVENT_PACKET, 0, event, sizeof(event));
|
||||||
|
socket_connection_send_packet(connection, HCI_EVENT_PACKET, 0, event, sizeof(event));
|
||||||
|
}
|
||||||
|
|
||||||
static void send_rfcomm_create_channel_failed(void * connection, bd_addr_t addr, uint8_t server_channel, uint8_t status){
|
static void send_rfcomm_create_channel_failed(void * connection, bd_addr_t addr, uint8_t server_channel, uint8_t status){
|
||||||
// emit error - see rfcom.c:rfcomm_emit_channel_open_failed_outgoing_memory(..)
|
// emit error - see rfcom.c:rfcomm_emit_channel_open_failed_outgoing_memory(..)
|
||||||
uint8_t event[16];
|
uint8_t event[16];
|
||||||
@ -823,7 +834,8 @@ static int btstack_command_handler(connection_t *connection, uint8_t *packet, ui
|
|||||||
case L2CAP_REGISTER_SERVICE:
|
case L2CAP_REGISTER_SERVICE:
|
||||||
psm = READ_BT_16(packet, 3);
|
psm = READ_BT_16(packet, 3);
|
||||||
mtu = READ_BT_16(packet, 5);
|
mtu = READ_BT_16(packet, 5);
|
||||||
l2cap_register_service_internal(connection, NULL, psm, mtu, LEVEL_0);
|
status = l2cap_register_service(NULL, psm, mtu, LEVEL_0);
|
||||||
|
l2cap_emit_service_registered(connection, status, psm);
|
||||||
break;
|
break;
|
||||||
case L2CAP_UNREGISTER_SERVICE:
|
case L2CAP_UNREGISTER_SERVICE:
|
||||||
psm = READ_BT_16(packet, 3);
|
psm = READ_BT_16(packet, 3);
|
||||||
|
@ -1616,7 +1616,7 @@ void bnep_register_service(void * connection, uint16_t service_uuid, uint16_t ma
|
|||||||
memset(service, 0, sizeof(bnep_service_t));
|
memset(service, 0, sizeof(bnep_service_t));
|
||||||
|
|
||||||
/* register with l2cap if not registered before, max MTU */
|
/* register with l2cap if not registered before, max MTU */
|
||||||
l2cap_register_service_internal(NULL, bnep_packet_handler, PSM_BNEP, 0xffff, bnep_security_level);
|
l2cap_register_service(bnep_packet_handler, PSM_BNEP, 0xffff, bnep_security_level);
|
||||||
|
|
||||||
/* Setup the service struct */
|
/* Setup the service struct */
|
||||||
service->connection = connection;
|
service->connection = connection;
|
||||||
|
@ -2258,7 +2258,7 @@ static void rfcomm_register_service2(void * connection, uint8_t channel, uint16_
|
|||||||
|
|
||||||
// register with l2cap if not registered before, max MTU
|
// register with l2cap if not registered before, max MTU
|
||||||
if (linked_list_empty(&rfcomm_services)){
|
if (linked_list_empty(&rfcomm_services)){
|
||||||
l2cap_register_service_internal(NULL, rfcomm_packet_handler, PSM_RFCOMM, 0xffff, rfcomm_security_level);
|
l2cap_register_service(rfcomm_packet_handler, PSM_RFCOMM, 0xffff, rfcomm_security_level);
|
||||||
}
|
}
|
||||||
|
|
||||||
// fill in
|
// fill in
|
||||||
|
@ -76,7 +76,7 @@ static uint16_t sdp_response_size = 0;
|
|||||||
|
|
||||||
void sdp_init(void){
|
void sdp_init(void){
|
||||||
// register with l2cap psm sevices - max MTU
|
// register with l2cap psm sevices - max MTU
|
||||||
l2cap_register_service_internal(NULL, sdp_packet_handler, PSM_SDP, 0xffff, LEVEL_0);
|
l2cap_register_service(sdp_packet_handler, PSM_SDP, 0xffff, LEVEL_0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// register packet handler
|
// register packet handler
|
||||||
|
30
src/l2cap.c
30
src/l2cap.c
@ -189,17 +189,6 @@ static void l2cap_emit_connection_parameter_update_response(uint16_t handle, uin
|
|||||||
(*packet_handler)(NULL, HCI_EVENT_PACKET, 0, event, sizeof(event));
|
(*packet_handler)(NULL, HCI_EVENT_PACKET, 0, event, sizeof(event));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void l2cap_emit_service_registered(void *connection, uint8_t status, uint16_t psm){
|
|
||||||
log_info("L2CAP_EVENT_SERVICE_REGISTERED status 0x%x psm 0x%x", status, psm);
|
|
||||||
uint8_t event[5];
|
|
||||||
event[0] = L2CAP_EVENT_SERVICE_REGISTERED;
|
|
||||||
event[1] = sizeof(event) - 2;
|
|
||||||
event[2] = status;
|
|
||||||
bt_store_16(event, 3, psm);
|
|
||||||
hci_dump_packet( HCI_EVENT_PACKET, 0, event, sizeof(event));
|
|
||||||
(*packet_handler)(connection, HCI_EVENT_PACKET, 0, event, sizeof(event));
|
|
||||||
}
|
|
||||||
|
|
||||||
static void l2cap_emit_credits(l2cap_channel_t *channel, uint8_t credits) {
|
static void l2cap_emit_credits(l2cap_channel_t *channel, uint8_t credits) {
|
||||||
|
|
||||||
log_info("L2CAP_EVENT_CREDITS local_cid 0x%x credits %u", channel->local_cid, credits);
|
log_info("L2CAP_EVENT_CREDITS local_cid 0x%x credits %u", channel->local_cid, credits);
|
||||||
@ -1535,32 +1524,30 @@ static inline l2cap_service_t * l2cap_get_service(uint16_t psm){
|
|||||||
return l2cap_get_service_internal(&l2cap_services, psm);
|
return l2cap_get_service_internal(&l2cap_services, psm);
|
||||||
}
|
}
|
||||||
|
|
||||||
void l2cap_register_service_internal(void *connection, btstack_packet_handler_t service_packet_handler, uint16_t psm, uint16_t mtu, gap_security_level_t security_level){
|
|
||||||
|
uint8_t l2cap_register_service(btstack_packet_handler_t service_packet_handler, uint16_t psm, uint16_t mtu, gap_security_level_t security_level){
|
||||||
|
|
||||||
log_info("L2CAP_REGISTER_SERVICE psm 0x%x mtu %u connection %p", psm, mtu, connection);
|
log_info("L2CAP_REGISTER_SERVICE psm 0x%x mtu %u", psm, mtu);
|
||||||
|
|
||||||
// check for alread registered psm
|
// check for alread registered psm
|
||||||
// TODO: emit error event
|
// TODO: emit error event
|
||||||
l2cap_service_t *service = l2cap_get_service(psm);
|
l2cap_service_t *service = l2cap_get_service(psm);
|
||||||
if (service) {
|
if (service) {
|
||||||
log_error("l2cap_register_service_internal: PSM %u already registered", psm);
|
log_error("l2cap_register_service: PSM %u already registered", psm);
|
||||||
l2cap_emit_service_registered(connection, L2CAP_SERVICE_ALREADY_REGISTERED, psm);
|
return L2CAP_SERVICE_ALREADY_REGISTERED;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// alloc structure
|
// alloc structure
|
||||||
// TODO: emit error event
|
// TODO: emit error event
|
||||||
service = btstack_memory_l2cap_service_get();
|
service = btstack_memory_l2cap_service_get();
|
||||||
if (!service) {
|
if (!service) {
|
||||||
log_error("l2cap_register_service_internal: no memory for l2cap_service_t");
|
log_error("l2cap_register_service: no memory for l2cap_service_t");
|
||||||
l2cap_emit_service_registered(connection, BTSTACK_MEMORY_ALLOC_FAILED, psm);
|
return BTSTACK_MEMORY_ALLOC_FAILED;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// fill in
|
// fill in
|
||||||
service->psm = psm;
|
service->psm = psm;
|
||||||
service->mtu = mtu;
|
service->mtu = mtu;
|
||||||
service->connection = connection;
|
|
||||||
service->packet_handler = service_packet_handler;
|
service->packet_handler = service_packet_handler;
|
||||||
service->required_security_level = security_level;
|
service->required_security_level = security_level;
|
||||||
|
|
||||||
@ -1570,8 +1557,7 @@ void l2cap_register_service_internal(void *connection, btstack_packet_handler_t
|
|||||||
// enable page scan
|
// enable page scan
|
||||||
hci_connectable_control(1);
|
hci_connectable_control(1);
|
||||||
|
|
||||||
// done
|
return 0;
|
||||||
l2cap_emit_service_registered(connection, 0, psm);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void l2cap_unregister_service_internal(void *connection, uint16_t psm){
|
void l2cap_unregister_service_internal(void *connection, uint16_t psm){
|
||||||
|
13
src/l2cap.h
13
src/l2cap.h
@ -184,7 +184,7 @@ typedef struct {
|
|||||||
uint16_t mps;
|
uint16_t mps;
|
||||||
|
|
||||||
// client connection
|
// client connection
|
||||||
void *connection;
|
void * connection;
|
||||||
|
|
||||||
// internal connection
|
// internal connection
|
||||||
btstack_packet_handler_t packet_handler;
|
btstack_packet_handler_t packet_handler;
|
||||||
@ -252,9 +252,9 @@ uint16_t l2cap_get_remote_mtu_for_local_cid(uint16_t local_cid);
|
|||||||
int l2cap_send_internal(uint16_t local_cid, uint8_t *data, uint16_t len);
|
int l2cap_send_internal(uint16_t local_cid, uint8_t *data, uint16_t len);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Registers L2CAP service with given PSM and MTU, and assigns a packet handler. On embedded systems, use NULL for connection parameter.
|
* @brief Registers L2CAP service with given PSM and MTU, and assigns a packet handler.
|
||||||
*/
|
*/
|
||||||
void l2cap_register_service(btstack_packet_handler_t packet_handler, uint16_t psm, uint16_t mtu, gap_security_level_t security_level);
|
uint8_t l2cap_register_service(btstack_packet_handler_t packet_handler, uint16_t psm, uint16_t mtu, gap_security_level_t security_level);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Unregisters L2CAP service with given PSM. On embedded systems, use NULL for connection parameter.
|
* @brief Unregisters L2CAP service with given PSM. On embedded systems, use NULL for connection parameter.
|
||||||
@ -297,15 +297,10 @@ int l2cap_send_connectionless(uint16_t handle, uint16_t cid, uint8_t *data, uin
|
|||||||
|
|
||||||
// deprecated...
|
// deprecated...
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Registers L2CAP service with given PSM and MTU, and assigns a packet handler. On embedded systems, use NULL for connection parameter.
|
|
||||||
*/
|
|
||||||
void l2cap_register_service_internal(void *connection, btstack_packet_handler_t packet_handler, uint16_t psm, uint16_t mtu, gap_security_level_t security_level);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Unregisters L2CAP service with given PSM. On embedded systems, use NULL for connection parameter.
|
* @brief Unregisters L2CAP service with given PSM. On embedded systems, use NULL for connection parameter.
|
||||||
*/
|
*/
|
||||||
void l2cap_unregister_service_internal(void *connection, uint16_t psm);
|
void l2cap_unregister_service_internal(void * connection, uint16_t psm);
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
|
|
||||||
|
@ -162,7 +162,7 @@ int btstack_main(int argc, const char * argv[]){
|
|||||||
|
|
||||||
l2cap_init();
|
l2cap_init();
|
||||||
l2cap_register_packet_handler(&packet_handler2);
|
l2cap_register_packet_handler(&packet_handler2);
|
||||||
l2cap_register_service_internal(NULL, packet_handler, PSM_SDP, 100, LEVEL_0);
|
l2cap_register_service(packet_handler, PSM_SDP, 100, LEVEL_0);
|
||||||
|
|
||||||
// turn on!
|
// turn on!
|
||||||
hci_power_control(HCI_POWER_ON);
|
hci_power_control(HCI_POWER_ON);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user