1 /******************************************************************************
2 *
3 * Copyright 2009-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 * Filename: btif_pan_internal.h
22 *
23 * Description: Bluetooth pan internal
24 *
25 ******************************************************************************/
26
27 #ifndef BTIF_PAN_INTERNAL_H
28 #define BTIF_PAN_INTERNAL_H
29
30 #include "bt_types.h"
31 #include "btif_pan.h"
32
33 /*******************************************************************************
34 * Constants & Macros
35 ******************************************************************************/
36
37 #define PAN_NAP_SERVICE_NAME "Android Network Access Point"
38 #define PANU_SERVICE_NAME "Android Network User"
39 #define TAP_IF_NAME "bt-pan"
40 #define TAP_MAX_PKT_WRITE_LEN 2000
41
42 #define PAN_STATE_OPEN 1
43 #define PAN_STATE_CLOSE 2
44 #ifndef PAN_ROLE_INACTIVE
45 #define PAN_ROLE_INACTIVE 0
46 #endif
47
48 /*******************************************************************************
49 * Type definitions and return values
50 ******************************************************************************/
51
52 typedef struct eth_hdr {
53 RawAddress h_dest;
54 RawAddress h_src;
55 short h_proto;
56 } tETH_HDR;
57
58 typedef struct {
59 int handle;
60 int state;
61 uint16_t protocol;
62 RawAddress peer;
63 int local_role;
64 int remote_role;
65 RawAddress eth_addr;
66 } btpan_conn_t;
67
68 typedef struct {
69 int btl_if_handle;
70 int btl_if_handle_panu;
71 int tap_fd;
72 int enabled;
73 int open_count;
74 int flow; // 1: outbound data flow on; 0: outbound data flow off
75 btpan_conn_t conns[MAX_PAN_CONNS];
76 int congest_packet_size;
77 unsigned char congest_packet[1600]; // max ethernet packet size
78 } btpan_cb_t;
79
80 /*******************************************************************************
81 * Functions
82 ******************************************************************************/
83
84 extern btpan_cb_t btpan_cb;
85 btpan_conn_t* btpan_new_conn(int handle, const RawAddress& addr, int local_role,
86 int peer_role);
87 btpan_conn_t* btpan_find_conn_addr(const RawAddress& addr);
88 btpan_conn_t* btpan_find_conn_handle(uint16_t handle);
89 void btpan_set_flow_control(bool enable);
90 int btpan_get_connected_count(void);
91 int btpan_tap_open(void);
92 void create_tap_read_thread(int tap_fd);
93 void destroy_tap_read_thread(void);
94 int btpan_tap_close(int tap_fd);
95 int btpan_tap_send(int tap_fd, const RawAddress& src, const RawAddress& dst,
96 uint16_t protocol, const char* buff, uint16_t size, bool ext,
97 bool forward);
98
is_empty_eth_addr(const RawAddress & addr)99 static inline int is_empty_eth_addr(const RawAddress& addr) {
100 return addr == RawAddress::kEmpty;
101 }
102
is_valid_bt_eth_addr(const RawAddress & addr)103 static inline int is_valid_bt_eth_addr(const RawAddress& addr) {
104 if (is_empty_eth_addr(addr)) return 0;
105 return addr.address[0] & 1 ? 0 : 1; /* Cannot be multicasting address */
106 }
107
108 #endif
109