bta_pan_api.c revision 3576c564b33c20b5e2e90fdd3bca7ce24392ca50
1/******************************************************************************
2 *
3 *  Copyright (C) 2004-2012 Broadcom Corporation
4 *
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:
8 *
9 *  http://www.apache.org/licenses/LICENSE-2.0
10 *
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.
16 *
17 ******************************************************************************/
18
19/******************************************************************************
20 *
21 *  This is the implementation of the API for PAN subsystem of BTA,
22 *  Broadcom's Bluetooth application layer for mobile phones.
23 *
24 ******************************************************************************/
25
26#include "bt_target.h"
27
28#include "bta_api.h"
29#include "bta_sys.h"
30#include "pan_api.h"
31#include "gki.h"
32#include "bta_pan_api.h"
33#include "bta_pan_int.h"
34#include "bd.h"
35#include <string.h>
36#include "bt_utils.h"
37
38#if defined(BTA_PAN_INCLUDED) && (BTA_PAN_INCLUDED == TRUE)
39
40static const tBTA_SYS_REG bta_pan_reg =
41{
42    bta_pan_hdl_event,
43    BTA_PanDisable
44};
45
46/*******************************************************************************
47**
48** Function         BTA_PanEnable
49**
50** Description      Enable PAN service.  This function must be
51**                  called before any other functions in the PAN API are called.
52**                  When the enable operation is complete the callback function
53**                  will be called with a BTA_PAN_ENABLE_EVT.
54**
55** Returns          void
56**
57*******************************************************************************/
58void BTA_PanEnable(tBTA_PAN_CBACK p_cback)
59{
60    tBTA_PAN_API_ENABLE  *p_buf;
61
62    /* register with BTA system manager */
63    GKI_sched_lock();
64    bta_sys_register(BTA_ID_PAN, &bta_pan_reg);
65    GKI_sched_unlock();
66
67    if ((p_buf = (tBTA_PAN_API_ENABLE *) GKI_getbuf(sizeof(tBTA_PAN_API_ENABLE))) != NULL)
68    {
69        p_buf->hdr.event = BTA_PAN_API_ENABLE_EVT;
70        p_buf->p_cback = p_cback;
71
72        bta_sys_sendmsg(p_buf);
73    }
74}
75
76
77
78/*******************************************************************************
79**
80** Function         BTA_PanDisable
81**
82** Description      Disables PAN service.
83**
84**
85** Returns          void
86**
87*******************************************************************************/
88void BTA_PanDisable(void)
89{
90    BT_HDR  *p_buf;
91
92    bta_sys_deregister(BTA_ID_PAN);
93    if ((p_buf = (BT_HDR *) GKI_getbuf(sizeof(BT_HDR))) != NULL)
94    {
95        p_buf->event = BTA_PAN_API_DISABLE_EVT;
96        bta_sys_sendmsg(p_buf);
97    }
98}
99
100/*******************************************************************************
101**
102** Function         BTA_PanSetRole
103**
104** Description      Sets PAN roles. When the enable operation is complete
105**                  the callback function will be called with a BTA_PAN_SET_ROLE_EVT.
106**
107** Returns          void
108**
109*******************************************************************************/
110void BTA_PanSetRole(tBTA_PAN_ROLE role, tBTA_PAN_ROLE_INFO *p_user_info, tBTA_PAN_ROLE_INFO *p_gn_info,
111                                        tBTA_PAN_ROLE_INFO *p_nap_info)
112{
113
114    tBTA_PAN_API_SET_ROLE  *p_buf;
115
116    if ((p_buf = (tBTA_PAN_API_SET_ROLE *) GKI_getbuf(sizeof(tBTA_PAN_API_SET_ROLE))) != NULL)
117    {
118        p_buf->hdr.event = BTA_PAN_API_SET_ROLE_EVT;
119        p_buf->role = role;
120
121        if(p_user_info && (role & BTA_PAN_ROLE_PANU))
122        {
123            if(p_user_info->p_srv_name)
124                BCM_STRNCPY_S(p_buf->user_name, sizeof(p_buf->user_name), p_user_info->p_srv_name, BTA_SERVICE_NAME_LEN);
125            else
126                p_buf->user_name[0] = 0;
127
128            p_buf->user_name[BTA_SERVICE_NAME_LEN] = 0;
129            p_buf->user_app_id = p_user_info->app_id;
130            p_buf->user_sec_mask = p_user_info->sec_mask;
131        }
132
133        if(p_gn_info && (role & BTA_PAN_ROLE_GN))
134        {
135            if(p_gn_info->p_srv_name)
136                BCM_STRNCPY_S(p_buf->gn_name, sizeof(p_buf->gn_name), p_gn_info->p_srv_name, BTA_SERVICE_NAME_LEN);
137            else
138                p_buf->gn_name[0] = 0;
139
140            p_buf->gn_name[BTA_SERVICE_NAME_LEN] = 0;
141            p_buf->gn_app_id = p_gn_info->app_id;
142            p_buf->gn_sec_mask = p_gn_info->sec_mask;
143
144        }
145
146        if(p_nap_info && (role & BTA_PAN_ROLE_NAP))
147        {
148            if(p_nap_info->p_srv_name)
149                BCM_STRNCPY_S(p_buf->nap_name, sizeof(p_buf->nap_name), p_nap_info->p_srv_name, BTA_SERVICE_NAME_LEN);
150            else
151                p_buf->nap_name[0] = 0;
152
153            p_buf->nap_name[BTA_SERVICE_NAME_LEN] = 0;
154            p_buf->nap_app_id = p_nap_info->app_id;
155            p_buf->nap_sec_mask = p_nap_info->sec_mask;
156
157        }
158
159        bta_sys_sendmsg(p_buf);
160    }
161
162
163
164}
165
166/*******************************************************************************
167**
168** Function         BTA_PanOpen
169**
170** Description      Opens a connection to a peer device.
171**                  When connection is open callback function is called
172**                  with a BTA_PAN_OPEN_EVT.
173**
174**
175** Returns          void
176**
177*******************************************************************************/
178BTA_API void BTA_PanOpen(BD_ADDR bd_addr, tBTA_PAN_ROLE    local_role, tBTA_PAN_ROLE    peer_role)
179{
180
181    tBTA_PAN_API_OPEN  *p_buf;
182
183    if ((p_buf = (tBTA_PAN_API_OPEN *) GKI_getbuf(sizeof(tBTA_PAN_API_OPEN))) != NULL)
184    {
185        p_buf->hdr.event = BTA_PAN_API_OPEN_EVT;
186        p_buf->local_role = local_role;
187        p_buf->peer_role = peer_role;
188        bdcpy(p_buf->bd_addr, bd_addr);
189        bta_sys_sendmsg(p_buf);
190    }
191
192}
193
194/*******************************************************************************
195**
196** Function         BTA_PanClose
197**
198** Description      Close a PAN  connection to a peer device.
199**
200**
201** Returns          void
202**
203*******************************************************************************/
204BTA_API void BTA_PanClose(UINT16 handle)
205{
206    BT_HDR  *p_buf;
207
208    if ((p_buf = (BT_HDR *) GKI_getbuf(sizeof(BT_HDR))) != NULL)
209    {
210        p_buf->event = BTA_PAN_API_CLOSE_EVT;
211        p_buf->layer_specific = handle;
212        bta_sys_sendmsg(p_buf);
213    }
214}
215#else
216
217void BTA_PanEnable(tBTA_PAN_CBACK p_cback)
218{
219    UNUSED(p_cback);
220}
221
222void BTA_PanDisable(void)
223{
224}
225
226void BTA_PanSetRole(tBTA_PAN_ROLE role, tBTA_PAN_ROLE_INFO *p_user_info, tBTA_PAN_ROLE_INFO *p_gn_info,
227                    tBTA_PAN_ROLE_INFO *p_nap_info)
228{
229    UNUSED(role);
230    UNUSED(p_user_info);
231    UNUSED(p_gn_info);
232    UNUSED(p_nap_info);
233}
234
235void BTA_PanOpen(BD_ADDR bd_addr, tBTA_PAN_ROLE local_role, tBTA_PAN_ROLE peer_role)
236{
237    UNUSED(bd_addr);
238    UNUSED(local_role);
239    UNUSED(peer_role);
240}
241
242void BTA_PanClose(UINT16 handle)
243{
244    UNUSED(handle);
245}
246
247#endif /* BTA_PAN_INCLUDED */
248