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 } tPAN_CONN;
78 
79 /*  The main PAN control block
80  */
81 typedef struct {
82   tPAN_ROLE role;
83   tPAN_ROLE active_role;
84   tPAN_ROLE prv_active_role;
85   tPAN_CONN pcb[MAX_PAN_CONNS];
86 
87   tPAN_CONN_STATE_CB* pan_conn_state_cb; /* Connection state callback */
88   tPAN_BRIDGE_REQ_CB* pan_bridge_req_cb;
89   tPAN_DATA_IND_CB* pan_data_ind_cb;
90   tPAN_DATA_BUF_IND_CB* pan_data_buf_ind_cb;
91   tPAN_FILTER_IND_CB* pan_pfilt_ind_cb;  /* protocol filter indication callback */
92   tPAN_MFILTER_IND_CB* pan_mfilt_ind_cb; /* multicast filter indication callback */
93   tPAN_TX_DATA_FLOW_CB* pan_tx_data_flow_cb;
94 
95   char* user_service_name;
96   char* gn_service_name;
97   char* nap_service_name;
98   uint32_t pan_user_sdp_handle;
99   uint32_t pan_gn_sdp_handle;
100   uint32_t pan_nap_sdp_handle;
101   uint8_t num_conns;
102 } tPAN_CB;
103 
104 /* Global PAN data
105  */
106 extern tPAN_CB pan_cb;
107 
108 /******************************************************************************/
109 void pan_register_with_bnep(void);
110 void pan_conn_ind_cb(uint16_t handle, const RawAddress& p_bda, const bluetooth::Uuid& remote_uuid,
111                      const bluetooth::Uuid& local_uuid, bool is_role_change);
112 void pan_connect_state_cb(uint16_t handle, const RawAddress& rem_bda, tBNEP_RESULT result,
113                           bool is_role_change);
114 void pan_data_buf_ind_cb(uint16_t handle, const RawAddress& src, const RawAddress& dst,
115                          uint16_t protocol, BT_HDR* p_buf, bool ext);
116 void pan_tx_data_flow_cb(uint16_t handle, tBNEP_RESULT event);
117 void pan_proto_filt_ind_cb(uint16_t handle, bool indication, tBNEP_RESULT result,
118                            uint16_t num_filters, uint8_t* p_filters);
119 void pan_mcast_filt_ind_cb(uint16_t handle, bool indication, tBNEP_RESULT result,
120                            uint16_t num_filters, uint8_t* p_filters);
121 uint32_t pan_register_with_sdp(uint16_t uuid, const char* p_name, const char* p_desc);
122 tPAN_CONN* pan_allocate_pcb(const RawAddress& p_bda, uint16_t handle);
123 tPAN_CONN* pan_get_pcb_by_handle(uint16_t handle);
124 tPAN_CONN* pan_get_pcb_by_addr(const RawAddress& p_bda);
125 void pan_close_all_connections(void);
126 void pan_release_pcb(tPAN_CONN* p_pcb);
127 void pan_dump_status(void);
128 
129 /******************************************************************************/
130 
131 namespace std {
132 template <>
133 struct formatter<tPAN_STATE> : enum_formatter<tPAN_STATE> {};
134 }  // namespace std
135 
136 #endif
137