1 /******************************************************************************
3 * Copyright 2004-2012 Broadcom Corporation
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at:
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 ******************************************************************************/
19 /******************************************************************************
21 * This is the implementation of the API for PAN subsystem of BTA,
22 * Broadcom's Bluetooth application layer for mobile phones.
24 ******************************************************************************/
28 #include "bt_target.h" // Must be first to define build configuration
29 #if (BTA_PAN_INCLUDED == TRUE)
31 #include "bta/pan/bta_pan_int.h"
32 #include "osi/include/allocator.h"
33 #include "osi/include/compat.h"
34 #include "types/raw_address.h"
36 static const tBTA_SYS_REG bta_pan_reg = {bta_pan_hdl_event, BTA_PanDisable};
39 #define PAN_SECURITY \
40 (BTM_SEC_IN_AUTHENTICATE | BTM_SEC_OUT_AUTHENTICATE | BTM_SEC_IN_ENCRYPT | \
44 /*******************************************************************************
46 * Function BTA_PanEnable
48 * Description Enable PAN service. This function must be
49 * called before any other functions in the PAN API are called.
50 * When the enable operation is complete the callback function
51 * will be called with a BTA_PAN_ENABLE_EVT.
55 ******************************************************************************/
56 void BTA_PanEnable(tBTA_PAN_CBACK p_cback) {
57 tBTA_PAN_API_ENABLE* p_buf =
58 (tBTA_PAN_API_ENABLE*)osi_malloc(sizeof(tBTA_PAN_API_ENABLE));
60 /* register with BTA system manager */
61 bta_sys_register(BTA_ID_PAN, &bta_pan_reg);
63 p_buf->hdr.event = BTA_PAN_API_ENABLE_EVT;
64 p_buf->p_cback = p_cback;
66 bta_sys_sendmsg(p_buf);
69 /*******************************************************************************
71 * Function BTA_PanDisable
73 * Description Disables PAN service.
78 ******************************************************************************/
79 void BTA_PanDisable(void) {
80 BT_HDR_RIGID* p_buf = (BT_HDR_RIGID*)osi_malloc(sizeof(BT_HDR_RIGID));
82 bta_sys_deregister(BTA_ID_PAN);
83 p_buf->event = BTA_PAN_API_DISABLE_EVT;
85 bta_sys_sendmsg(p_buf);
88 /*******************************************************************************
90 * Function BTA_PanSetRole
92 * Description Sets PAN roles. When the enable operation is complete
93 * the callback function will be called with a
94 * BTA_PAN_SET_ROLE_EVT.
98 ******************************************************************************/
99 void BTA_PanSetRole(tBTA_PAN_ROLE role, tBTA_PAN_ROLE_INFO* p_user_info,
100 tBTA_PAN_ROLE_INFO* p_nap_info) {
101 tBTA_PAN_API_SET_ROLE* p_buf =
102 (tBTA_PAN_API_SET_ROLE*)osi_calloc(sizeof(tBTA_PAN_API_SET_ROLE));
104 p_buf->hdr.event = BTA_PAN_API_SET_ROLE_EVT;
107 if (role & BTA_PAN_ROLE_PANU) {
108 if (p_user_info->p_srv_name)
109 strlcpy(p_buf->user_name, p_user_info->p_srv_name, BTA_SERVICE_NAME_LEN);
111 p_buf->user_app_id = p_user_info->app_id;
114 if (role & BTA_PAN_ROLE_NAP) {
115 if (p_nap_info->p_srv_name)
116 strlcpy(p_buf->nap_name, p_nap_info->p_srv_name, BTA_SERVICE_NAME_LEN);
118 p_buf->nap_app_id = p_nap_info->app_id;
121 bta_sys_sendmsg(p_buf);
124 /*******************************************************************************
126 * Function BTA_PanOpen
128 * Description Opens a connection to a peer device.
129 * When connection is open callback function is called
130 * with a BTA_PAN_OPEN_EVT.
135 ******************************************************************************/
136 void BTA_PanOpen(const RawAddress& bd_addr, tBTA_PAN_ROLE local_role,
137 tBTA_PAN_ROLE peer_role) {
138 tBTA_PAN_API_OPEN* p_buf =
139 (tBTA_PAN_API_OPEN*)osi_malloc(sizeof(tBTA_PAN_API_OPEN));
141 p_buf->hdr.event = BTA_PAN_API_OPEN_EVT;
142 p_buf->local_role = local_role;
143 p_buf->peer_role = peer_role;
144 p_buf->bd_addr = bd_addr;
146 bta_sys_sendmsg(p_buf);
149 /*******************************************************************************
151 * Function BTA_PanClose
153 * Description Close a PAN connection to a peer device.
158 ******************************************************************************/
159 void BTA_PanClose(uint16_t handle) {
160 BT_HDR_RIGID* p_buf = (BT_HDR_RIGID*)osi_malloc(sizeof(BT_HDR_RIGID));
162 p_buf->event = BTA_PAN_API_CLOSE_EVT;
163 p_buf->layer_specific = handle;
165 bta_sys_sendmsg(p_buf);
168 #include "bta/pan/bta_pan_int.h"
169 #include "osi/include/osi.h" // UNUSED_ATTR
171 void BTA_PanEnable(UNUSED_ATTR tBTA_PAN_CBACK p_cback) {}
173 void BTA_PanDisable(void) {}
175 void BTA_PanSetRole(UNUSED_ATTR tBTA_PAN_ROLE role,
176 UNUSED_ATTR tBTA_PAN_ROLE_INFO* p_user_info,
177 UNUSED_ATTR tBTA_PAN_ROLE_INFO* p_gn_info,
178 UNUSED_ATTR tBTA_PAN_ROLE_INFO* p_nap_info) {}
180 void BTA_PanOpen(UNUSED_ATTR const RawAddress& bd_addr,
181 UNUSED_ATTR tBTA_PAN_ROLE local_role,
182 UNUSED_ATTR tBTA_PAN_ROLE peer_role) {}
184 void BTA_PanClose(UNUSED_ATTR uint16_t handle) {}
186 #endif /* BTA_PAN_INCLUDED */