dotstack API Reference  1.10.37
Macros | Functions
L2CAP

The Bluetooth logical link control and adaptation protocol (L2CAP) supports higher level protocol multiplexing, packet segmentation and reassembly, and the conveying of quality of service information. More...

Macros

#define bt_l2cap_listen(mgr, psm, acl_config, callback, param)   bt_l2cap_listen_ext(mgr, psm, CMODE_BASIC, acl_config, callback, param)
 Listen for incoming connections. More...
 
#define bt_l2cap_connect(mgr, remote_addr, psm, acl_config, connect_cb, param, state_cb)   bt_l2cap_connect_ext(mgr, remote_addr, psm, CMODE_BASIC, acl_config, connect_cb, param, state_cb)
 Connect to a remote device. More...
 

Functions

void bt_l2cap_init (void)
 Initialize the L2CAP layer. More...
 
bt_l2cap_mgr_tbt_l2cap_allocate_mgr (bt_hci_ctrl_state_t *hci_ctrl)
 Allocate L2CAP manager. More...
 
void bt_l2cap_free_mgr (bt_l2cap_mgr_t *mgr)
 Release L2CAP manger. More...
 
bt_bool bt_l2cap_listen_ext (bt_l2cap_mgr_t *mgr, bt_int psm, bt_byte chmode, bt_uint acl_config, bt_l2cap_listen_callback_fp callback, void *param)
 Listen for incoming connections. More...
 
bt_bool bt_l2cap_cancel_listen (bt_l2cap_mgr_t *mgr, bt_int psmId)
 Stop listening for incoming connections. More...
 
bt_bool bt_l2cap_listen_fixed_channel (bt_l2cap_mgr_t *mgr, bt_id cid, bt_byte link_type, bt_l2cap_listen_callback_fp callback, void *param)
 Listen for incoming connections. More...
 
bt_bool bt_l2cap_cancel_listen_fixed_channel (bt_l2cap_mgr_t *mgr, bt_id cid, bt_byte link_type)
 Stop listening for incoming connections. More...
 
bt_bool bt_l2cap_connect_ext (bt_l2cap_mgr_t *mgr, bt_bdaddr_t *remote_addr, bt_int psm, bt_byte chmode, bt_uint acl_config, bt_l2cap_connect_callback_fp connect_cb, void *param, bt_l2cap_state_changed_callback_fp state_cb)
 Connect to a remote device. More...
 
bt_bool bt_l2cap_connect_fixed_channel (bt_l2cap_mgr_t *mgr, bt_bdaddr_t *remote_addr, bt_id cid, bt_uint acl_config, bt_l2cap_connect_callback_fp connect_cb, void *param, bt_l2cap_state_changed_callback_fp state_cb)
 Connect to a remote device. More...
 
bt_bool bt_l2cap_disconnect (bt_l2cap_channel_t *ch)
 Close L2CAP channel. More...
 
bt_bool bt_l2cap_disconnect_ex (bt_l2cap_channel_t *pch, bt_bool force_hci_disconnect)
 Close L2CAP channel. More...
 
bt_bool bt_l2cap_is_channel_open (bt_l2cap_channel_t *channel)
 Check if channel is open. More...
 
bt_l2cap_mgr_tbt_l2cap_get_mgr (bt_hci_hconn_t h)
 Get the L2CAP manager. More...
 
bt_bool bt_l2cap_hci_has_open_channels (bt_hci_conn_state_t *conn)
 Check if there are open channels on an ACL connection. More...
 
bt_bool bt_l2cap_send_data (bt_l2cap_channel_t *channel, const bt_byte *data, bt_int len, bt_l2cap_send_data_callback_fp callback, void *cb_param)
 Send data over an L2CAP channel. More...
 

Detailed Description

The Bluetooth logical link control and adaptation protocol (L2CAP) supports higher level protocol multiplexing, packet segmentation and reassembly, and the conveying of quality of service information.

Macro Definition Documentation

#define bt_l2cap_connect (   mgr,
  remote_addr,
  psm,
  acl_config,
  connect_cb,
  param,
  state_cb 
)    bt_l2cap_connect_ext(mgr, remote_addr, psm, CMODE_BASIC, acl_config, connect_cb, param, state_cb)

Connect to a remote device.

This function establishes an L2CAP connection with a remote device on a specific PSM. When connect operation completes a callback function is called. An L2CAP channel will always be created in CMODE_BASIC mode.

Parameters
mgrThe L2CAP manager.
remote_addrThe address of the remote device.
psmThe PSM for the connection.
acl_configThe ACL link configuration. This can be one of the following values:
  • HCI_CONFIG_ENABLE_AUTHENTICATION - The ACL link will be authenticated if it is not already
  • HCI_CONFIG_ENABLE_ENCRYPTION - The ACL link will be encrypted if it is not already
  • HCI_CONFIG_BECOME_MASTER - The stack will try to make local device a master of the ACL link
connect_cbThe Callback function that is called when the connect operation completes.
paramA pointer to arbitrary data to be passed to the connect_cb callback.
state_cbThe callback function that is called when the state of the established connection changes.
Returns
  • TRUE when the function succeeds.
  • FALSE otherwise. None of the callback functions is called in this case.
#define bt_l2cap_listen (   mgr,
  psm,
  acl_config,
  callback,
  param 
)    bt_l2cap_listen_ext(mgr, psm, CMODE_BASIC, acl_config, callback, param)

Listen for incoming connections.

This function tells the L2CAP manager to listen for incoming connections on a specific PSM. When a connection is established a callback function is called. An L2CAP channel will always be created in CMODE_BASIC mode.

Parameters
mgrThe L2CAP manager.
psmThe PSM on which the manager will listen and accept incoming connections.
acl_configThe ACL link configuration. This can be a combination of the following values:
  • HCI_CONFIG_ENABLE_AUTHENTICATION - The ACL link will be authenticated if it is not already
  • HCI_CONFIG_ENABLE_ENCRYPTION - The ACL link will be encrypted if it is not already
  • HCI_CONFIG_BECOME_MASTER - The stack will try to make local device a master of the ACL link
callbackThe callback function that will be called when an incoming connection is established.
paramAn arbitrary data pointer that will be passed to the callback function specified by the callback parameter.
Returns
  • TRUE when the function succeeds.
  • FALSE otherwise. The callback function is not called in this case.

Function Documentation

bt_l2cap_mgr_t* bt_l2cap_allocate_mgr ( bt_hci_ctrl_state_t *  hci_ctrl)

Allocate L2CAP manager.

This function allocates and initializes an L2CAP manager structure. One L2CAP manager manages all L2CAP connections for a particular local device. The local device is specified by the hci_ctrl parameter.

Parameters
hci_ctrlPointer to the hci_ctrl_state structure that represents the local device (HCI controller) for which a L2CAP manager is to be allocated.
Returns
A pointer to the allocated L2CAP manager structure. The returned L2CAP manager should be freed by a call to bt_l2cap_free_mgr when it is no longer needed.
bt_bool bt_l2cap_cancel_listen ( bt_l2cap_mgr_t mgr,
bt_int  psmId 
)

Stop listening for incoming connections.

This function tells the L2CAP manager to stop listen for incoming connections on a specific PSM.

Parameters
mgrThe L2CAP manager.
psmThe PSM on which the manager will stop listening for incoming connections.
Returns
  • TRUE when the function succeeds.
  • FALSE otherwise. The callback function is not called in this case.
bt_bool bt_l2cap_cancel_listen_fixed_channel ( bt_l2cap_mgr_t mgr,
bt_id  cid,
bt_byte  link_type 
)

Stop listening for incoming connections.

This function tells the L2CAP manager to stop listen for incoming connections on a fixed channel.

Parameters
mgrThe L2CAP manager.
cidThe channel if on which the manager will stop listening.
linkThe type of the ACL link on which the manager will stop listening. This can be one of the following values:
  • L2CAP_LINK_TYPE_BD_EDR
  • L2CAP_LINK_TYPE_LE
Returns
  • TRUE when the function succeeds.
  • FALSE otherwise. The callback function is not called in this case.
bt_bool bt_l2cap_connect_ext ( bt_l2cap_mgr_t mgr,
bt_bdaddr_t *  remote_addr,
bt_int  psm,
bt_byte  chmode,
bt_uint  acl_config,
bt_l2cap_connect_callback_fp  connect_cb,
void *  param,
bt_l2cap_state_changed_callback_fp  state_cb 
)

Connect to a remote device.

This function establishes an L2CAP connection with a remote device on a specific PSM. When connect operation completes a callback function is called.

Parameters
mgrThe L2CAP manager.
remote_addrThe address of the remote device.
psmThe PSM for the connection.
chmodeThe desired mode of the L2CAP channel. The mode can be changed depending on the capabilities of the remote L2CAP entity. The chmode can be one of the following values:
  • CMODE_BASIC
  • CMODE_ERETR
  • CMODE_STRM
acl_configThe ACL link configuration. This can be a combination of the following values:
  • HCI_CONFIG_ENABLE_AUTHENTICATION - The ACL link will be authenticated if it is not already
  • HCI_CONFIG_ENABLE_ENCRYPTION - The ACL link will be encrypted if it is not already
  • HCI_CONFIG_BECOME_MASTER - The stack will try to make local device a master of the ACL link
connect_cbThe Callback function that is called when the connect operation completes.
paramA pointer to arbitrary data to be passed to the connect_cb callback.
state_cbThe callback function that is called when the state of the established connection changes.
Returns
  • TRUE when the function succeeds.
  • FALSE otherwise. None of the callback functions is called in this case.
bt_bool bt_l2cap_connect_fixed_channel ( bt_l2cap_mgr_t mgr,
bt_bdaddr_t *  remote_addr,
bt_id  cid,
bt_uint  acl_config,
bt_l2cap_connect_callback_fp  connect_cb,
void *  param,
bt_l2cap_state_changed_callback_fp  state_cb 
)

Connect to a remote device.

This function establishes an L2CAP connection with a remote device on a fixed channel. When connect operation completes a callback function is called.

Parameters
mgrThe L2CAP manager.
remote_addrThe address of the remote device.
cidThe channel id for the connection.
acl_configThe ACL link configuration. This can be one of the following values:
  • HCI_CONFIG_ENABLE_AUTHENTICATION - The ACL link will be authenticated if it is not already
  • HCI_CONFIG_ENABLE_ENCRYPTION - The ACL link will be encrypted if it is not already
  • HCI_CONFIG_BECOME_MASTER - The stack will try to make local device a master of the ACL link
connect_cbThe Callback function that is called when the connect operation completes.
paramA pointer to arbitrary data to be passed to the connect_cb callback.
state_cbThe callback function that is called when the state of the established connection changes.
Returns
  • TRUE when the function succeeds.
  • FALSE otherwise. None of the callback functions is called in this case.
bt_bool bt_l2cap_disconnect ( bt_l2cap_channel_t *  ch)

Close L2CAP channel.

This function closes an L2CAP channel. The channel can be established either by a call to bt_l2cap_connect() or by an incoming connection request.

Parameters
chThe L2CAP channel to be closed.
Returns
  • TRUE when the function succeeds.
  • FALSE otherwise. The callback function is not called in this case.
bt_bool bt_l2cap_disconnect_ex ( bt_l2cap_channel_t *  pch,
bt_bool  force_hci_disconnect 
)

Close L2CAP channel.

This function closes an L2CAP channel. The channel can be established either by a call to bt_l2cap_connect() or by an incoming connection request.

Parameters
chThe L2CAP channel to be closed.
force_hci_disconnectDefines if the ACL link has also to be closed.
Returns
  • TRUE when the function succeeds.
  • FALSE otherwise. The callback function is not called in this case.
void bt_l2cap_free_mgr ( bt_l2cap_mgr_t mgr)

Release L2CAP manger.

This function releases the L2CAP manager structure.

Parameters
mgrThe L2CAP manager structure to be released.
bt_l2cap_mgr_t* bt_l2cap_get_mgr ( bt_hci_hconn_t  h)

Get the L2CAP manager.

This function returns the L2CAP manager which manager the specified ACL connection.

Parameters
hACL connection handle
Returns
The L2CAP manager.
bt_bool bt_l2cap_hci_has_open_channels ( bt_hci_conn_state_t *  conn)

Check if there are open channels on an ACL connection.

This function checks if there are open channels on a specified ACL connection.

Parameters
connACL connection
Returns
  • TRUE if the ACL has at least open L2CAP channel.
  • FALSE otherwise.
void bt_l2cap_init ( void  )

Initialize the L2CAP layer.

This function initializes the L2CAP layer of the stack. It must be called prior to any other L2CAP function can be called.

bt_bool bt_l2cap_is_channel_open ( bt_l2cap_channel_t *  channel)

Check if channel is open.

This function checks if an L2CAP channel is open.

Parameters
channelL2CAP channel
Returns
  • TRUE if the channel is open.
  • FALSE if the channel is closed.
bt_bool bt_l2cap_listen_ext ( bt_l2cap_mgr_t mgr,
bt_int  psm,
bt_byte  chmode,
bt_uint  acl_config,
bt_l2cap_listen_callback_fp  callback,
void *  param 
)

Listen for incoming connections.

This function tells the L2CAP manager to listen for incoming connections on a specific PSM. When a connection is established a callback function is called.

Parameters
mgrThe L2CAP manager.
psmThe PSM on which the manager will listen and accept incoming connections.
chmodeThe desired mode of the L2CAP channel. The mode can be changed depending on the capabilities of the remote L2CAP entity. The chmode can be one of the following values:
  • CMODE_BASIC
  • CMODE_ERETR
  • CMODE_STRM
acl_configThe ACL link configuration. This can be a combination of the following values:
  • HCI_CONFIG_ENABLE_AUTHENTICATION - The ACL link will be authenticated if it is not already
  • HCI_CONFIG_ENABLE_ENCRYPTION - The ACL link will be encrypted if it is not already
  • HCI_CONFIG_BECOME_MASTER - The stack will try to make local device a master of the ACL link
callbackThe callback function that will be called when an incoming connection is established.
paramAn arbitrary data pointer that will be passed to the callback function specified by the callback parameter.
Returns
  • TRUE when the function succeeds.
  • FALSE otherwise. The callback function is not called in this case.
bt_bool bt_l2cap_listen_fixed_channel ( bt_l2cap_mgr_t mgr,
bt_id  cid,
bt_byte  link_type,
bt_l2cap_listen_callback_fp  callback,
void *  param 
)

Listen for incoming connections.

This function tells the L2CAP manager to listen for incoming connections on a fixed channel. When a connection is established a callback function is called.

Parameters
mgrThe L2CAP manager.
cidThe channel if on which the manager will listen and accept incoming connections.
link_typeThe type of the ACL link on with the manager will listen. This can be one of the following values:
  • L2CAP_LINK_TYPE_BD_EDR
  • L2CAP_LINK_TYPE_LE
callbackThe callback function that will be called when an incoming connection is established.
paramAn arbitrary data pointer that will be passed to the callback function specified by the callback parameter.
Returns
  • TRUE when the function succeeds.
  • FALSE otherwise. The callback function is not called in this case.
bt_bool bt_l2cap_send_data ( bt_l2cap_channel_t *  channel,
const bt_byte *  data,
bt_int  len,
bt_l2cap_send_data_callback_fp  callback,
void *  cb_param 
)

Send data over an L2CAP channel.

This function sends data over the specified L2CAP channel.

1 int i;
2 
3 i = 1;
Parameters
channelThe L2CAP channel to send data over.
dataThe pointer to the data.
lenThe length of the data.
callbackThe callback function that is called when sending the data has been completed.
Returns
  • TRUE if the function succeeds.
  • FALSE otherwise. The callback function is not called in this case.