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 public interface file for the Personal Area Networking (PAN)
22  *  subsystem of BTA, Broadcom's Bluetooth application layer for mobile
23  *  phones.
24  *
25  ******************************************************************************/
26 #ifndef BTA_PAN_API_H
27 #define BTA_PAN_API_H
28 
29 #include "bta_api.h"
30 #include "pan_api.h"
31 
32 /*****************************************************************************
33  *  Constants and data types
34  ****************************************************************************/
35 #define BTA_PAN_SUCCESS 0
36 #define BTA_PAN_FAIL 1
37 
38 typedef uint8_t tBTA_PAN_STATUS;
39 
40 /* PAN Callback events */
41 #define BTA_PAN_ENABLE_EVT 0   /* PAN service is enabled. */
42 #define BTA_PAN_SET_ROLE_EVT 1 /* PAN roles registered */
43 #define BTA_PAN_OPENING_EVT 2  /* Connection is being opened. */
44 #define BTA_PAN_OPEN_EVT 3     /* Connection has been opened. */
45 #define BTA_PAN_CLOSE_EVT 4    /* Connection has been closed. */
46 
47 typedef uint8_t tBTA_PAN_EVT;
48 
49 /* pan roles */
50 #define BTA_PAN_ROLE_PANU PAN_ROLE_CLIENT
51 #define BTA_PAN_ROLE_GN PAN_ROLE_GN_SERVER
52 #define BTA_PAN_ROLE_NAP PAN_ROLE_NAP_SERVER
53 
54 typedef uint8_t tBTA_PAN_ROLE;
55 
56 /*  information regarding PAN roles */
57 typedef struct {
58   const char* p_srv_name; /* service name for the PAN role */
59   uint8_t app_id;         /* application id */
60   tBTA_SEC sec_mask;      /* security setting for the role */
61 
62 } tBTA_PAN_ROLE_INFO;
63 
64 /* Event associated with BTA_PAN_SET_ROLE_EVT */
65 typedef struct {
66   tBTA_PAN_STATUS status; /* status of set role event */
67   tBTA_PAN_ROLE role;     /* PAN roles successfully registered */
68 } tBTA_PAN_SET_ROLE;
69 
70 /* Event associated with BTA_PAN_OPENING_EVT */
71 typedef struct {
72   RawAddress bd_addr; /* BD address of peer device. */
73   uint16_t handle; /* Handle associated with this connection. */
74 
75 } tBTA_PAN_OPENING;
76 
77 /* Event associated with BTA_PAN_OPEN_EVT */
78 typedef struct {
79   RawAddress bd_addr;       /* BD address of peer device. */
80   uint16_t handle;          /* Handle associated with this connection. */
81   tBTA_PAN_STATUS status;   /* status of open event */
82   tBTA_PAN_ROLE local_role; /* Local device PAN role for the connection */
83   tBTA_PAN_ROLE peer_role;  /* Peer device PAN role for the connection */
84 
85 } tBTA_PAN_OPEN;
86 
87 /* Event associated with BTA_PAN_CLOSE_EVT */
88 typedef struct {
89   uint16_t handle; /* Handle associated with the connection. */
90 } tBTA_PAN_CLOSE;
91 
92 /* Union of all PAN callback structures */
93 typedef union {
94   tBTA_PAN_SET_ROLE set_role; /* set_role event */
95   tBTA_PAN_OPEN open;         /* Connection has been opened. */
96   tBTA_PAN_OPENING opening;   /* Connection being opened */
97   tBTA_PAN_CLOSE close;       /* Connection has been closed. */
98 } tBTA_PAN;
99 
100 /* Number of PAN connections */
101 #ifndef BTA_PAN_NUM_CONN
102 #define BTA_PAN_NUM_CONN 4
103 #endif
104 
105 /* PAN callback */
106 typedef void(tBTA_PAN_CBACK)(tBTA_PAN_EVT event, tBTA_PAN* p_data);
107 
108 /*****************************************************************************
109  *  External Function Declarations
110  ****************************************************************************/
111 
112 /*******************************************************************************
113  *
114  * Function         BTA_PanEnable
115  *
116  * Description      Enable PAN service.  This function must be
117  *                  called before any other functions in the PAN API are called.
118  *                  When the enable operation is complete the callback function
119  *                  will be called with a BTA_PAN_ENABLE_EVT.
120  *
121  * Returns          void
122  *
123  ******************************************************************************/
124 extern void BTA_PanEnable(tBTA_PAN_CBACK p_cback);
125 
126 /*******************************************************************************
127  *
128  * Function         BTA_PanDisable
129  *
130  * Description      Disable PAN service.
131  *
132  * Returns          void
133  *
134  ******************************************************************************/
135 extern void BTA_PanDisable(void);
136 
137 /*******************************************************************************
138  *
139  * Function         BTA_PanSetRole
140  *
141  * Description      Sets PAN roles. When the enable operation is complete
142  *                  the callback function will be called with a
143  *                  BTA_PAN_SET_ROLE_EVT.
144  *
145  * Returns          void
146  *
147  ******************************************************************************/
148 void BTA_PanSetRole(tBTA_PAN_ROLE role, tBTA_PAN_ROLE_INFO* p_user_info,
149                     tBTA_PAN_ROLE_INFO* p_gn_info,
150                     tBTA_PAN_ROLE_INFO* p_nap_info);
151 
152 /*******************************************************************************
153  *
154  * Function         BTA_PanOpen
155  *
156  * Description      Opens a connection to a peer device.
157  *                  When connection is open callback function is called
158  *                  with a BTA_PAN_OPEN_EVT.
159  *
160  *
161  * Returns          void
162  *
163  ******************************************************************************/
164 void BTA_PanOpen(const RawAddress& bd_addr, tBTA_PAN_ROLE local_role,
165                  tBTA_PAN_ROLE peer_role);
166 
167 /*******************************************************************************
168  *
169  * Function         BTA_PanClose
170  *
171  * Description      Close a PAN  connection to a peer device.
172  *
173  *
174  * Returns          void
175  *
176  ******************************************************************************/
177 extern void BTA_PanClose(uint16_t handle);
178 
179 #endif /* BTA_PAN_API_H */
180