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