1 /******************************************************************************
3 * Copyright (C) 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 ******************************************************************************/
26 #include "bt_target.h"
31 #include "bt_common.h"
32 #include "bta_pan_api.h"
33 #include "bta_pan_int.h"
37 #if defined(BTA_PAN_INCLUDED) && (BTA_PAN_INCLUDED == TRUE)
39 static const tBTA_SYS_REG bta_pan_reg =
45 /*******************************************************************************
47 ** Function BTA_PanEnable
49 ** Description Enable PAN service. This function must be
50 ** called before any other functions in the PAN API are called.
51 ** When the enable operation is complete the callback function
52 ** will be called with a BTA_PAN_ENABLE_EVT.
56 *******************************************************************************/
57 void BTA_PanEnable(tBTA_PAN_CBACK p_cback)
59 tBTA_PAN_API_ENABLE *p_buf =
60 (tBTA_PAN_API_ENABLE *)osi_malloc(sizeof(tBTA_PAN_API_ENABLE));
62 /* register with BTA system manager */
63 bta_sys_register(BTA_ID_PAN, &bta_pan_reg);
65 p_buf->hdr.event = BTA_PAN_API_ENABLE_EVT;
66 p_buf->p_cback = p_cback;
68 bta_sys_sendmsg(p_buf);
73 /*******************************************************************************
75 ** Function BTA_PanDisable
77 ** Description Disables PAN service.
82 *******************************************************************************/
83 void BTA_PanDisable(void)
85 BT_HDR *p_buf = (BT_HDR *)osi_malloc(sizeof(BT_HDR));
87 bta_sys_deregister(BTA_ID_PAN);
88 p_buf->event = BTA_PAN_API_DISABLE_EVT;
90 bta_sys_sendmsg(p_buf);
93 /*******************************************************************************
95 ** Function BTA_PanSetRole
97 ** Description Sets PAN roles. When the enable operation is complete
98 ** the callback function will be called with a BTA_PAN_SET_ROLE_EVT.
102 *******************************************************************************/
103 void BTA_PanSetRole(tBTA_PAN_ROLE role, tBTA_PAN_ROLE_INFO *p_user_info, tBTA_PAN_ROLE_INFO *p_gn_info,
104 tBTA_PAN_ROLE_INFO *p_nap_info)
106 tBTA_PAN_API_SET_ROLE *p_buf =
107 (tBTA_PAN_API_SET_ROLE *)osi_malloc(sizeof(tBTA_PAN_API_SET_ROLE));
109 p_buf->hdr.event = BTA_PAN_API_SET_ROLE_EVT;
112 if (p_user_info && (role & BTA_PAN_ROLE_PANU)) {
113 if (p_user_info->p_srv_name)
114 strlcpy(p_buf->user_name, p_user_info->p_srv_name, BTA_SERVICE_NAME_LEN);
116 p_buf->user_name[0] = 0;
118 p_buf->user_app_id = p_user_info->app_id;
119 p_buf->user_sec_mask = p_user_info->sec_mask;
122 if (p_gn_info && (role & BTA_PAN_ROLE_GN)) {
123 if (p_gn_info->p_srv_name)
124 strlcpy(p_buf->gn_name, p_gn_info->p_srv_name, BTA_SERVICE_NAME_LEN);
126 p_buf->gn_name[0] = 0;
128 p_buf->gn_app_id = p_gn_info->app_id;
129 p_buf->gn_sec_mask = p_gn_info->sec_mask;
132 if (p_nap_info && (role & BTA_PAN_ROLE_NAP)) {
133 if (p_nap_info->p_srv_name)
134 strlcpy(p_buf->nap_name, p_nap_info->p_srv_name, BTA_SERVICE_NAME_LEN);
136 p_buf->nap_name[0] = 0;
138 p_buf->nap_app_id = p_nap_info->app_id;
139 p_buf->nap_sec_mask = p_nap_info->sec_mask;
143 bta_sys_sendmsg(p_buf);
146 /*******************************************************************************
148 ** Function BTA_PanOpen
150 ** Description Opens a connection to a peer device.
151 ** When connection is open callback function is called
152 ** with a BTA_PAN_OPEN_EVT.
157 *******************************************************************************/
158 void BTA_PanOpen(BD_ADDR bd_addr, tBTA_PAN_ROLE local_role, tBTA_PAN_ROLE peer_role)
160 tBTA_PAN_API_OPEN *p_buf =
161 (tBTA_PAN_API_OPEN *)osi_malloc(sizeof(tBTA_PAN_API_OPEN));
163 p_buf->hdr.event = BTA_PAN_API_OPEN_EVT;
164 p_buf->local_role = local_role;
165 p_buf->peer_role = peer_role;
166 bdcpy(p_buf->bd_addr, bd_addr);
168 bta_sys_sendmsg(p_buf);
171 /*******************************************************************************
173 ** Function BTA_PanClose
175 ** Description Close a PAN connection to a peer device.
180 *******************************************************************************/
181 void BTA_PanClose(UINT16 handle)
183 BT_HDR *p_buf = (BT_HDR *)osi_malloc(sizeof(BT_HDR));
185 p_buf->event = BTA_PAN_API_CLOSE_EVT;
186 p_buf->layer_specific = handle;
188 bta_sys_sendmsg(p_buf);
192 void BTA_PanEnable(tBTA_PAN_CBACK p_cback)
197 void BTA_PanDisable(void)
201 void BTA_PanSetRole(tBTA_PAN_ROLE role, tBTA_PAN_ROLE_INFO *p_user_info, tBTA_PAN_ROLE_INFO *p_gn_info,
202 tBTA_PAN_ROLE_INFO *p_nap_info)
210 void BTA_PanOpen(BD_ADDR bd_addr, tBTA_PAN_ROLE local_role, tBTA_PAN_ROLE peer_role)
217 void BTA_PanClose(UINT16 handle)
222 #endif /* BTA_PAN_INCLUDED */