blob: 485a905f689767d562b1acec262c9821f1019192 [file] [log] [blame]
The Android Open Source Project5738f832012-12-12 16:00:35 -08001/******************************************************************************
2 *
3 * Copyright (C) 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 "btif_pan.h"
31#include "bt_types.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 ETH_ADDR_LEN 6
Hemant Gupta6ba8fda2014-10-15 19:59:23 +053041#define TAP_MAX_PKT_WRITE_LEN 2000
The Android Open Source Project5738f832012-12-12 16:00:35 -080042#ifndef PAN_SECURITY
43#define PAN_SECURITY (BTM_SEC_IN_AUTHENTICATE | BTM_SEC_OUT_AUTHENTICATE | BTM_SEC_IN_ENCRYPT | BTM_SEC_OUT_ENCRYPT)
44#endif
45
46#define PAN_STATE_UNKNOWN 0
47#define PAN_STATE_OPEN 1
48#define PAN_STATE_CLOSE 2
49#ifndef PAN_ROLE_INACTIVE
50#define PAN_ROLE_INACTIVE 0
51#endif
52
53
54/*******************************************************************************
55** Type definitions and return values
56********************************************************************************/
57
58typedef struct eth_hdr
59{
60 unsigned char h_dest[ETH_ADDR_LEN];
61 unsigned char h_src[ETH_ADDR_LEN];
62 short h_proto;
63} tETH_HDR;
64
65typedef struct
66{
67 int handle;
68 int state;
Marie Janssenb7f64bc2016-06-22 12:52:19 -070069 uint16_t protocol;
The Android Open Source Project5738f832012-12-12 16:00:35 -080070 BD_ADDR peer;
71 int local_role;
72 int remote_role;
73 unsigned char eth_addr[ETH_ADDR_LEN];
74} btpan_conn_t;
75
76typedef struct
77{
78 int btl_if_handle;
79 int btl_if_handle_panu;
80 int tap_fd;
81 int enabled;
82 int open_count;
Sharvil Nanavati4186b0e2014-04-07 13:52:37 -070083 int flow; // 1: outbound data flow on; 0: outbound data flow off
The Android Open Source Project5738f832012-12-12 16:00:35 -080084 btpan_conn_t conns[MAX_PAN_CONNS];
Sharvil Nanavati4186b0e2014-04-07 13:52:37 -070085 int congest_packet_size;
86 unsigned char congest_packet[1600]; //max ethernet packet size
The Android Open Source Project5738f832012-12-12 16:00:35 -080087} btpan_cb_t;
88
89
90/*******************************************************************************
91** Functions
92********************************************************************************/
93
94extern btpan_cb_t btpan_cb;
95btpan_conn_t *btpan_new_conn(int handle, const BD_ADDR addr, int local_role, int peer_role);
96btpan_conn_t *btpan_find_conn_addr(const BD_ADDR addr);
Marie Janssenb7f64bc2016-06-22 12:52:19 -070097btpan_conn_t *btpan_find_conn_handle(uint16_t handle);
98void btpan_set_flow_control(bool enable);
The Android Open Source Project5738f832012-12-12 16:00:35 -080099int btpan_get_connected_count(void);
100int btpan_tap_open(void);
101void create_tap_read_thread(int tap_fd);
102void destroy_tap_read_thread(void);
103int btpan_tap_close(int tap_fd);
Marie Janssenb7f64bc2016-06-22 12:52:19 -0700104int btpan_tap_send(int tap_fd, const BD_ADDR src, const BD_ADDR dst, uint16_t protocol,
105 const char* buff, uint16_t size, bool ext, bool forward);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800106
107static inline int is_empty_eth_addr(const BD_ADDR addr)
108{
109 int i;
110 for(i = 0; i < BD_ADDR_LEN; i++)
111 if(addr[i] != 0)
112 return 0;
113 return 1;
114}
115
116static inline int is_valid_bt_eth_addr(const BD_ADDR addr)
117{
118 if(is_empty_eth_addr(addr))
119 return 0;
120 return addr[0] & 1 ? 0 : 1; /* Cannot be multicasting address */
121}
122
The Android Open Source Project5738f832012-12-12 16:00:35 -0800123#endif