#include <bt/bt_acl_pkt_buf.h>
Defines | |
#define | BT_PSM_DATA_CB |
Service Routine Definition. | |
Errors | |
#define | BT_PSM_ERR_BUF_OVERFLOW -7 |
#define | BT_PSM_ERR_INVALID_PSM -1 |
#define | BT_PSM_ERR_INVALID_SERVICE_NR -5 |
#define | BT_PSM_ERR_NO_SERVICE_REGISTERED -6 |
#define | BT_PSM_ERR_PSM_IN_USE -2 |
#define | BT_PSM_ERR_SERVICE_PORTS_EXHAUSTED -3 |
Typedefs | |
typedef bt_acl_pkt_buf *(*) | bt_psm_data_cb_t (bt_acl_pkt_buf *pkt_buf, u_char *data, u_short len, u_short service_nr, void *cb_arg) |
typedef bt_psm_s | bt_psm_t |
Protocol / service multiplexor typedef. | |
Functions | |
short | bt_psm_deliver_msg (bt_psm_t *mux, bt_acl_pkt_buf *pkt_buf, u_char *data, u_short len, u_short psm, bt_acl_pkt_buf **free_buf_p) |
Delivers a received message to a registered service. | |
u_short | bt_psm_get_nr_default_bufs (bt_psm_t *psmux) |
Returns the number of the free ACL packet buffers available. | |
bt_psm_data_cb_t | bt_psm_service_patch (bt_psm_t *psmux, u_short psm, bt_psm_data_cb_t data_cb) |
Patch registered service. | |
Initialization | |
bt_psm_t * | bt_psm_init (struct btstack *bt_stack, u_short nr_services, u_short nr_bufs) |
Application Interface | |
short | bt_psm_service_clear (bt_psm_t *mux, u_short service_nr) |
Clears a previousely registered service. | |
long | bt_psm_service_register (bt_psm_t *psmux, u_short psm, BT_PSM_DATA_CB, void *cb_arg) |
Registers a higher layer service at the protocol / service multiplexor. | |
short | bt_psm_service_set_buffers (bt_psm_t *mux, u_short service_nr, bt_acl_pkt_buf **free_bufs) |
Sets the packet buffers a registered service shall use. |
#define BT_PSM_DATA_CB |
Value:
bt_acl_pkt_buf* (*data_cb) (bt_acl_pkt_buf* pkt_buf, \ u_char* data, \ u_short len, \ u_short service_nr, \ void* cb_arg)
A service routine handles incoming data and has to be specified by the application during service registration (see bt_psm_service_register). This defines how a service routine has to look like.
msg | Pointer to the received ACL packet buffer (incoming packets are encapsulated in ACL packet buffers) | |
data | Pointer to the payload of the packet | |
len | Size of the packet's payload | |
service_nr | Number of the service this callback corresponds to | |
arg | Pointer to the (optional) callback argument. |
#define BT_PSM_ERR_BUF_OVERFLOW -7 |
The service to deliver does not provide enough free buffers
#define BT_PSM_ERR_INVALID_PSM -1 |
The psm specified is not valid
#define BT_PSM_ERR_INVALID_SERVICE_NR -5 |
The service number passed does not identify a registered service
#define BT_PSM_ERR_NO_SERVICE_REGISTERED -6 |
The psm field in the data packet received is valid but there is no service registered on that psm
#define BT_PSM_ERR_PSM_IN_USE -2 |
The psm specified is used by another registered service
#define BT_PSM_ERR_SERVICE_PORTS_EXHAUSTED -3 |
No more services can be registered to the connection-less data channel
typedef bt_acl_pkt_buf*(*) bt_psm_data_cb_t(bt_acl_pkt_buf *pkt_buf, u_char *data, u_short len, u_short service_nr, void *cb_arg) |
BT_PSM_DATA_CB as type bt_psm_data_cb_t
short bt_psm_deliver_msg | ( | bt_psm_t * | mux, | |
bt_acl_pkt_buf * | pkt_buf, | |||
u_char * | data, | |||
u_short | len, | |||
u_short | psm, | |||
bt_acl_pkt_buf ** | free_buf_p | |||
) |
Delivers a received message to a registered service.
Delivers the received message msg
to the service registered at PSM psm
. The parameters data
and len
are passed to the higher layer service via the registered data callback (see BT_PSM_DATA_CB). Thus, data
should be a pointer to the payload of the packet, while data_len
should be set to the lenght of the payload.
Note: applications typically do not call this function! This function is used by lower layer protocols (e.g. l2cap connection-less) to deliver received messages to higher layer protocols / services (e.g. multi-hop layer, application service).
mux | Pointer to the protocol / service multiplexor | |
msg | Pointer to the message to be delivered | |
data | Pointer to the payload of the message | |
len | Size of the payload | |
psm | The PSM the message msg will be delivered to | |
free_msg | Reference to a free packet buffer pointer: the protocol / service multiplexor will store a pointer to a free message buffer in the reference passed. If there is no free packet buffer available, the buffer msg passed will be returned. |
Initializes a protocol / service multiplexor.
Note: The bt-stack, and the ACL layer, have to be initialized before calling this function. Thus, make shure that:
bt_stack | Pointer to the bt-stack to use | |
nr_services | Defines the maximal number of services the multiplexor can handle. | |
nr_bufs | Number of packet buffers to use |
Clears a previousely registered service.
Clears the registered service with service nr service_nr
.
Note: dedicated buffers beloning to the service to be cleared are not destroyed.
stack | Pointer to the connection-less l2cap stack | |
service_nr | Service number of the service to clear |
bt_psm_data_cb_t bt_psm_service_patch | ( | bt_psm_t * | psmux, | |
u_short | psm, | |||
bt_psm_data_cb_t | data_cb | |||
) |
Patch registered service.
stack | Pointer to the connection-less l2cap stack | |
psm | of service to intercept | |
BT_PSM_DATA_CB | Data callback function to register. |
Registers a higher layer service at the protocol / service multiplexor.
After calling this function, packets received on PSM psm
are passed to the registering service. That is, each time a packet is received, the registered service is signalled by calling the service routine BT_PSM_DATA_CB
.
psmux | Pointer to the multiplexor to use | |
psm | The PSM to register on | |
BT_PSM_DATA_CB | Data callback function to register. | |
cb_arg | Callback argument |
// PSM your service uses #define SERVICE_PSM 0x1009 // data reception funtion of your service _service_data_rcv_cb(...) { ... } int main(void) { bt_psm_t* psmux; long service_nr; ... // initialize protocol/service multiplexor psmux = bt_psm_init(bt_stack, 6, 6); // register your service servic_nr = bt_psm_service_register(psmux, SERVICE_PSM, _service_data_rcv_cb, NULL); ... }
u_char data[12]; strcpy(data, "hello world"); l2cap_cl_send(data, <con_handle>, SERVICE_PSM, 12);
short bt_psm_service_set_buffers | ( | bt_psm_t * | mux, | |
u_short | service_nr, | |||
bt_acl_pkt_buf ** | free_bufs | |||
) |
Sets the packet buffers a registered service shall use.
Call this function if your service needs extra buffers or if you'd like to turn off packet buffering completely. If extra buffers are defined, incoming messages are buffered as long as free buffers can be found in free_bufs
.
mux | Pointer to the protocol/service multiplexor | |
servic_nr | Service number of the registered service | |
free_bufs | Pointer to an initialized packet buffer queue (see bt_acl_pkt_queue_create). Pass NULL if buffering shall be disabled. |
// PSM your service uses #define SERVICE_PSM 0x1009 // pointer to extra buffers bt_acl_pkt_buf* bufs; // data reception funtion of your service bt_msg_t* _service_data_rcv_cb(...) { ... } int main(void) { bt_psm_t* psmux; long service_nr; ... // initialize protocol/service multiplexor psmux = bt_psm_init(bt_stack, 6, 6); // register your service servic_nr = bt_psm_service_register(psmux, SERVICE_PSM, _service_data_rcv_cb, NULL); // create extra buffers bufs = bt_acl_pkt_que_create(6); bt_psm_service_set_buffers(psmux, service_nr, bufs); ... }