1 /******************************************************************************
2  *
3  *  Copyright 2001-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 file contains internally used PAN definitions
22  *
23  ******************************************************************************/
24 
25 #ifndef PAN_INT_H
26 #define PAN_INT_H
27 
28 #include <bluetooth/log.h>
29 
30 #include <cstdint>
31 
32 #include "internal_include/bt_target.h"
33 #include "stack/include/bt_hdr.h"
34 #include "stack/include/pan_api.h"
35 #include "types/bluetooth/uuid.h"
36 #include "types/raw_address.h"
37 
38 /*
39  * This role is used to shutdown the profile. Used internally
40  * Applications should call PAN_Deregister to shutdown the profile
41  */
42 #define PAN_ROLE_INACTIVE 0
43 
44 #define PAN_PROFILE_VERSION 0x0100 /* Version 1.00 */
45 
46 typedef enum : uint8_t {
47   PAN_STATE_IDLE = 0,
48   PAN_STATE_CONN_START = 1,
49   PAN_STATE_CONNECTED = 2,
50 } tPAN_STATE;
51 
52 /* Define the PAN Connection Control Block
53  */
54 typedef struct {
55   tPAN_STATE con_state;
56 
57 #define PAN_FLAGS_CONN_COMPLETED 0x01
58   uint8_t con_flags;
59 
60   uint16_t handle;
61   RawAddress rem_bda;
62 
63   uint16_t bad_pkts_rcvd;
64   uint16_t src_uuid;
65   uint16_t dst_uuid;
66   uint16_t prv_src_uuid;
67   uint16_t prv_dst_uuid;
68   uint16_t ip_addr_known;
69   uint32_t ip_addr;
70 
71   struct {
72     size_t octets{0};
73     size_t packets{0};
74     size_t errors{0};
75     size_t drops{0};
76   } write, read;
77 
78 } tPAN_CONN;
79 
80 /*  The main PAN control block
81  */
82 typedef struct {
83   tPAN_ROLE role;
84   tPAN_ROLE active_role;
85   tPAN_ROLE prv_active_role;
86   tPAN_CONN pcb[MAX_PAN_CONNS];
87 
88   tPAN_CONN_STATE_CB* pan_conn_state_cb; /* Connection state callback */
89   tPAN_BRIDGE_REQ_CB* pan_bridge_req_cb;
90   tPAN_DATA_IND_CB* pan_data_ind_cb;
91   tPAN_DATA_BUF_IND_CB* pan_data_buf_ind_cb;
92   tPAN_FILTER_IND_CB*
93       pan_pfilt_ind_cb; /* protocol filter indication callback */
94   tPAN_MFILTER_IND_CB*
95       pan_mfilt_ind_cb; /* multicast filter indication callback */
96   tPAN_TX_DATA_FLOW_CB* pan_tx_data_flow_cb;
97 
98   char* user_service_name;
99   char* gn_service_name;
100   char* nap_service_name;
101   uint32_t pan_user_sdp_handle;
102   uint32_t pan_gn_sdp_handle;
103   uint32_t pan_nap_sdp_handle;
104   uint8_t num_conns;
105 } tPAN_CB;
106 
107 /* Global PAN data
108  */
109 extern tPAN_CB pan_cb;
110 
111 /******************************************************************************/
112 void pan_register_with_bnep(void);
113 void pan_conn_ind_cb(uint16_t handle, const RawAddress& p_bda,
114                      const bluetooth::Uuid& remote_uuid,
115                      const bluetooth::Uuid& local_uuid, bool is_role_change);
116 void pan_connect_state_cb(uint16_t handle, const RawAddress& rem_bda,
117                           tBNEP_RESULT result, bool is_role_change);
118 void pan_data_buf_ind_cb(uint16_t handle, const RawAddress& src,
119                          const RawAddress& dst, uint16_t protocol,
120                          BT_HDR* p_buf, bool ext);
121 void pan_tx_data_flow_cb(uint16_t handle, tBNEP_RESULT event);
122 void pan_proto_filt_ind_cb(uint16_t handle, bool indication,
123                            tBNEP_RESULT result, uint16_t num_filters,
124                            uint8_t* p_filters);
125 void pan_mcast_filt_ind_cb(uint16_t handle, bool indication,
126                            tBNEP_RESULT result, uint16_t num_filters,
127                            uint8_t* p_filters);
128 uint32_t pan_register_with_sdp(uint16_t uuid, const char* p_name,
129                                const char* p_desc);
130 tPAN_CONN* pan_allocate_pcb(const RawAddress& p_bda, uint16_t handle);
131 tPAN_CONN* pan_get_pcb_by_handle(uint16_t handle);
132 tPAN_CONN* pan_get_pcb_by_addr(const RawAddress& p_bda);
133 void pan_close_all_connections(void);
134 void pan_release_pcb(tPAN_CONN* p_pcb);
135 void pan_dump_status(void);
136 
137 /******************************************************************************/
138 
139 namespace fmt {
140 template <>
141 struct formatter<tPAN_STATE> : enum_formatter<tPAN_STATE> {};
142 }  // namespace fmt
143 
144 #endif
145