1# 2 3## L2CAP Events {#sec:eventsAndErrorsAppendix} 4 5L2CAP events and data packets are delivered to the packet handler 6specified by *l2cap_register_service* resp. 7*l2cap_create_channel*. Data packets have the 8L2CAP_DATA_PACKET packet type. L2CAP provides the following events: 9 10- L2CAP_EVENT_CHANNEL_OPENED - sent if channel establishment is 11 done. Status not equal zero indicates an error. Possible errors: out 12 of memory; connection terminated by local host, when the connection 13 to remote device fails. 14 15- L2CAP_EVENT_CHANNEL_CLOSED - emitted when channel is closed. No 16 status information is provided. 17 18- L2CAP_EVENT_INCOMING_CONNECTION - received when the connection is 19 requested by remote. Connection accept and decline are performed 20 with *l2cap_accept_connection* and *l2cap_decline_connecti-on* respectively. 21 22- L2CAP_EVENT_CAN_SEND_NOW - Indicates that an L2CAP data packet could 23 be sent on the reported l2cap_cid. It is emitted after a call to 24 *l2cap_request_can_send_now*. See [Sending L2CAP Data](protocols/#sec:l2capSendProtocols) 25 Please note that the guarantee that a packet can be sent is only valid when the event is received. 26 After returning from the packet handler, BTstack might need to send itself. 27 28Event | Event Code 29-----------|---------------------------------------- 30L2CAP_EVENT_CHANNEL_OPENED | 0x70 31L2CAP_EVENT_CHANNEL_CLOSED | 0x71 32L2CAP_EVENT_INCOMING_CONNECTION | 0x72 33L2CAP_EVENT_CAN_SEND_NOW | 0x78 34 35Table: L2CAP Events. {#tbl:l2capEvents} 36 37L2CAP event paramaters, with size in bits: 38 39- L2CAP_EVENT_CHANNEL_OPENED: 40 - *event(8), len(8), status(8), address(48), handle(16), psm(16), local_cid(16), remote_cid(16), local_mtu(16), remote_mtu(16)* 41- L2CAP_EVENT_CHANNEL_CLOSED: 42 - *event (8), len(8), channel(16)* 43- L2CAP_EVENT_INCOMING_CONNECTION: 44 - *event(8), len(8), address(48), handle(16), psm (16), local_cid(16), remote_cid (16)* 45- L2CAP_EVENT_CAN_SEND_NOW: 46 - *event(8), len(8), local_cid(16) 47 48## RFCOMM Events 49 50All RFCOMM events and data packets are currently delivered to the packet 51handler specified by *rfcomm_register_packet_handler*. Data packets 52have the _DATA_PACKET packet type. Here is the list of events provided 53by RFCOMM: 54 55- RFCOMM_EVENT_INCOMING_CONNECTION - received when the connection 56 is requested by remote. Connection accept and decline are performed 57 with *rfcomm_accept_connection* and 58 *rfcomm_decline_connection* respectively. 59 60- RFCOMM_EVENT_CHANNEL_CLOSED - emitted when channel is closed. No 61 status information is provided. 62 63- RFCOMM_EVENT_CHANNEL_OPENED - sent if channel 64 establishment is done. Status not equal zero indicates an error. 65 Possible errors: an L2CAP error, out of memory. 66 67- RFCOMM_EVENT_CAN_SEND_NOW - Indicates that an RFCOMM data packet could 68 be sent on the reported rfcomm_cid. It is emitted after a call to 69 *rfcomm_request_can_send_now*. See [Sending RFCOMM Data](protocols/#sec:rfcommSendProtocols) 70 Please note that the guarantee that a packet can be sent is only valid when the event is received. 71 After returning from the packet handler, BTstack might need to send itself. 72 73 74Event | Event Code 75-----------|----------------------------- 76RFCOMM_EVENT_CHANNEL_OPENED | 0x80 77RFCOMM_EVENT_CHANNEL_CLOSED | 0x81 78RFCOMM_EVENT_INCOMING_CONNECTION | 0x82 79RFCOMM_EVENT_CAN_SEND_NOW | 0x89 80 81Table: RFCOMM Events. {#tbl:rfcommEvents} 82 83 84RFCOMM event paramaters, with size in bits: 85 86- RFCOMM_EVENT_CHANNEL_OPENED: 87 - *event(8), len(8), status(8), address(48), handle(16), server_channel(8), rfcomm_cid(16), max_frame_size(16)* 88- RFCOMM_EVENT_CHANNEL_CLOSED: 89 - *event(8), len(8), rfcomm_cid(16)* 90- RFCOMM_EVENT_INCOMING_CONNECTION: 91 - *event(8), len(8), address(48), channel (8), rfcomm_cid(16)* 92- RFCOMM_EVENT_CAN_SEND_NOW: 93 - *event(8), len(8), rfcomm_cid(16) 94 95## Errors {#sec:errorsAppendix} 96 97 98Error | Error Code 99------------------------------------------------------------------------|------------------- 100BTSTACK_MEMORY_ALLOC_FAILED | 0x56 101BTSTACK_ACL_BUFFERS_FULL | 0x57 102L2CAP_COMMAND_REJECT_REASON_COMMAND_NOT_UNDERSTOOD | 0x60 103L2CAP_COMMAND_REJECT_REASON_SIGNALING_MTU_EXCEEDED | 0x61 104L2CAP_COMMAND_REJECT_REASON_INVALID_CID_IN_REQUEST | 0x62 105L2CAP_CONNECTION_RESPONSE_RESULT_SUCCESSFUL | 0x63 106L2CAP_CONNECTION_RESPONSE_RESULT_PENDING | 0x64 107L2CAP_CONNECTION_RESPONSE_RESULT_REFUSED_PSM | 0x65 108L2CAP_CONNECTION_RESPONSE_RESULT_REFUSED_SECURITY | 0x66 109L2CAP_CONNECTION_RESPONSE_RESULT_REFUSED_RESOURCES | 0x65 110L2CAP_CONFIG_RESPONSE_RESULT_SUCCESSFUL | 0x66 111L2CAP_CONFIG_RESPONSE_RESULT_UNACCEPTABLE_PARAMS | 0x67 112L2CAP_CONFIG_RESPONSE_RESULT_REJECTED | 0x68 113L2CAP_CONFIG_RESPONSE_RESULT_UNKNOWN_OPTIONS | 0x69 114L2CAP_SERVICE_ALREADY_REGISTERED | 0x6a 115RFCOMM_MULTIPLEXER_STOPPED | 0x70 116RFCOMM_NO_OUTGOING_CREDITS | 0x72 117SDP_HANDLE_ALREADY_REGISTERED | 0x80 118 119Table: Errors. {#tbl:errors} 120 121