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