1 /******************************************************************************
2 *
3 * Copyright 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 <cstdint>
27
28 #include "bt_target.h" // Must be first to define build configuration
29 #if (BTA_PAN_INCLUDED == TRUE)
30
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"
35
36 static const tBTA_SYS_REG bta_pan_reg = {bta_pan_hdl_event, BTA_PanDisable};
37
38 #ifndef PAN_SECURITY
39 #define PAN_SECURITY \
40 (BTM_SEC_IN_AUTHENTICATE | BTM_SEC_OUT_AUTHENTICATE | BTM_SEC_IN_ENCRYPT | \
41 BTM_SEC_OUT_ENCRYPT)
42 #endif
43
44 /*******************************************************************************
45 *
46 * Function BTA_PanEnable
47 *
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.
52 *
53 * Returns void
54 *
55 ******************************************************************************/
BTA_PanEnable(tBTA_PAN_CBACK p_cback)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));
59
60 /* register with BTA system manager */
61 bta_sys_register(BTA_ID_PAN, &bta_pan_reg);
62
63 p_buf->hdr.event = BTA_PAN_API_ENABLE_EVT;
64 p_buf->p_cback = p_cback;
65
66 bta_sys_sendmsg(p_buf);
67 }
68
69 /*******************************************************************************
70 *
71 * Function BTA_PanDisable
72 *
73 * Description Disables PAN service.
74 *
75 *
76 * Returns void
77 *
78 ******************************************************************************/
BTA_PanDisable(void)79 void BTA_PanDisable(void) {
80 BT_HDR_RIGID* p_buf = (BT_HDR_RIGID*)osi_malloc(sizeof(BT_HDR_RIGID));
81
82 bta_sys_deregister(BTA_ID_PAN);
83 p_buf->event = BTA_PAN_API_DISABLE_EVT;
84
85 bta_sys_sendmsg(p_buf);
86 }
87
88 /*******************************************************************************
89 *
90 * Function BTA_PanSetRole
91 *
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.
95 *
96 * Returns void
97 *
98 ******************************************************************************/
BTA_PanSetRole(tBTA_PAN_ROLE role,tBTA_PAN_ROLE_INFO * p_user_info,tBTA_PAN_ROLE_INFO * p_nap_info)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));
103
104 p_buf->hdr.event = BTA_PAN_API_SET_ROLE_EVT;
105 p_buf->role = role;
106
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);
110
111 p_buf->user_app_id = p_user_info->app_id;
112 }
113
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);
117
118 p_buf->nap_app_id = p_nap_info->app_id;
119 }
120
121 bta_sys_sendmsg(p_buf);
122 }
123
124 /*******************************************************************************
125 *
126 * Function BTA_PanOpen
127 *
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.
131 *
132 *
133 * Returns void
134 *
135 ******************************************************************************/
BTA_PanOpen(const RawAddress & bd_addr,tBTA_PAN_ROLE local_role,tBTA_PAN_ROLE peer_role)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));
140
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;
145
146 bta_sys_sendmsg(p_buf);
147 }
148
149 /*******************************************************************************
150 *
151 * Function BTA_PanClose
152 *
153 * Description Close a PAN connection to a peer device.
154 *
155 *
156 * Returns void
157 *
158 ******************************************************************************/
BTA_PanClose(uint16_t handle)159 void BTA_PanClose(uint16_t handle) {
160 BT_HDR_RIGID* p_buf = (BT_HDR_RIGID*)osi_malloc(sizeof(BT_HDR_RIGID));
161
162 p_buf->event = BTA_PAN_API_CLOSE_EVT;
163 p_buf->layer_specific = handle;
164
165 bta_sys_sendmsg(p_buf);
166 }
167 #else
168 #include "bta/pan/bta_pan_int.h"
169 #include "osi/include/osi.h" // UNUSED_ATTR
170
BTA_PanEnable(UNUSED_ATTR tBTA_PAN_CBACK p_cback)171 void BTA_PanEnable(UNUSED_ATTR tBTA_PAN_CBACK p_cback) {}
172
BTA_PanDisable(void)173 void BTA_PanDisable(void) {}
174
BTA_PanSetRole(UNUSED_ATTR tBTA_PAN_ROLE role,UNUSED_ATTR tBTA_PAN_ROLE_INFO * p_user_info,UNUSED_ATTR tBTA_PAN_ROLE_INFO * p_gn_info,UNUSED_ATTR tBTA_PAN_ROLE_INFO * p_nap_info)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) {}
179
BTA_PanOpen(UNUSED_ATTR const RawAddress & bd_addr,UNUSED_ATTR tBTA_PAN_ROLE local_role,UNUSED_ATTR tBTA_PAN_ROLE peer_role)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) {}
183
BTA_PanClose(UNUSED_ATTR uint16_t handle)184 void BTA_PanClose(UNUSED_ATTR uint16_t handle) {}
185
186 #endif /* BTA_PAN_INCLUDED */
187