blob: ba863a5abedbdba1812ded968261c20e0e431293 [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 *
Myles Watsonee96a3c2016-11-23 14:49:54 -080025 ******************************************************************************/
The Android Open Source Project5738f832012-12-12 16:00:35 -080026
27#ifndef BTIF_PAN_INTERNAL_H
28#define BTIF_PAN_INTERNAL_H
29
The Android Open Source Project5738f832012-12-12 16:00:35 -080030#include "bt_types.h"
Myles Watson6bd442f2016-10-19 09:50:22 -070031#include "btif_pan.h"
The Android Open Source Project5738f832012-12-12 16:00:35 -080032
33/*******************************************************************************
Myles Watson6bd442f2016-10-19 09:50:22 -070034 * Constants & Macros
Myles Watsonee96a3c2016-11-23 14:49:54 -080035 ******************************************************************************/
The Android Open Source Project5738f832012-12-12 16:00:35 -080036
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"
Hemant Gupta6ba8fda2014-10-15 19:59:23 +053040#define TAP_MAX_PKT_WRITE_LEN 2000
The Android Open Source Project5738f832012-12-12 16:00:35 -080041#ifndef PAN_SECURITY
Myles Watson6bd442f2016-10-19 09:50:22 -070042#define PAN_SECURITY \
43 (BTM_SEC_IN_AUTHENTICATE | BTM_SEC_OUT_AUTHENTICATE | BTM_SEC_IN_ENCRYPT | \
44 BTM_SEC_OUT_ENCRYPT)
The Android Open Source Project5738f832012-12-12 16:00:35 -080045#endif
46
Myles Watson6bd442f2016-10-19 09:50:22 -070047#define PAN_STATE_UNKNOWN 0
48#define PAN_STATE_OPEN 1
49#define PAN_STATE_CLOSE 2
The Android Open Source Project5738f832012-12-12 16:00:35 -080050#ifndef PAN_ROLE_INACTIVE
51#define PAN_ROLE_INACTIVE 0
52#endif
53
The Android Open Source Project5738f832012-12-12 16:00:35 -080054/*******************************************************************************
Myles Watson6bd442f2016-10-19 09:50:22 -070055 * Type definitions and return values
Myles Watsonee96a3c2016-11-23 14:49:54 -080056 ******************************************************************************/
The Android Open Source Project5738f832012-12-12 16:00:35 -080057
Myles Watson6bd442f2016-10-19 09:50:22 -070058typedef struct eth_hdr {
Jakub Pawlowskia83ac122017-06-15 11:53:33 -070059 bt_bdaddr_t h_dest;
60 bt_bdaddr_t h_src;
Myles Watson6bd442f2016-10-19 09:50:22 -070061 short h_proto;
The Android Open Source Project5738f832012-12-12 16:00:35 -080062} tETH_HDR;
63
Myles Watson6bd442f2016-10-19 09:50:22 -070064typedef struct {
65 int handle;
66 int state;
67 uint16_t protocol;
Jakub Pawlowskia83ac122017-06-15 11:53:33 -070068 bt_bdaddr_t peer;
Myles Watson6bd442f2016-10-19 09:50:22 -070069 int local_role;
70 int remote_role;
Jakub Pawlowskia83ac122017-06-15 11:53:33 -070071 bt_bdaddr_t eth_addr;
The Android Open Source Project5738f832012-12-12 16:00:35 -080072} btpan_conn_t;
73
Myles Watson6bd442f2016-10-19 09:50:22 -070074typedef struct {
75 int btl_if_handle;
76 int btl_if_handle_panu;
77 int tap_fd;
78 int enabled;
79 int open_count;
80 int flow; // 1: outbound data flow on; 0: outbound data flow off
81 btpan_conn_t conns[MAX_PAN_CONNS];
82 int congest_packet_size;
83 unsigned char congest_packet[1600]; // max ethernet packet size
The Android Open Source Project5738f832012-12-12 16:00:35 -080084} btpan_cb_t;
85
The Android Open Source Project5738f832012-12-12 16:00:35 -080086/*******************************************************************************
Myles Watson6bd442f2016-10-19 09:50:22 -070087 * Functions
Myles Watsonee96a3c2016-11-23 14:49:54 -080088 ******************************************************************************/
The Android Open Source Project5738f832012-12-12 16:00:35 -080089
90extern btpan_cb_t btpan_cb;
Jakub Pawlowskia83ac122017-06-15 11:53:33 -070091btpan_conn_t* btpan_new_conn(int handle, const bt_bdaddr_t& addr,
92 int local_role, int peer_role);
93btpan_conn_t* btpan_find_conn_addr(const bt_bdaddr_t& addr);
Myles Watson6bd442f2016-10-19 09:50:22 -070094btpan_conn_t* btpan_find_conn_handle(uint16_t handle);
Marie Janssenb7f64bc2016-06-22 12:52:19 -070095void btpan_set_flow_control(bool enable);
The Android Open Source Project5738f832012-12-12 16:00:35 -080096int btpan_get_connected_count(void);
97int btpan_tap_open(void);
98void create_tap_read_thread(int tap_fd);
99void destroy_tap_read_thread(void);
100int btpan_tap_close(int tap_fd);
Jakub Pawlowskia83ac122017-06-15 11:53:33 -0700101int btpan_tap_send(int tap_fd, const bt_bdaddr_t& src, const bt_bdaddr_t& dst,
Myles Watson6bd442f2016-10-19 09:50:22 -0700102 uint16_t protocol, const char* buff, uint16_t size, bool ext,
103 bool forward);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800104
Jakub Pawlowskia83ac122017-06-15 11:53:33 -0700105static inline int is_empty_eth_addr(const bt_bdaddr_t& addr) {
Jakub Pawlowskib7b74732017-06-19 11:35:07 -0700106 return addr == bd_addr_empty;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800107}
108
Jakub Pawlowskia83ac122017-06-15 11:53:33 -0700109static inline int is_valid_bt_eth_addr(const bt_bdaddr_t& addr) {
Myles Watson6bd442f2016-10-19 09:50:22 -0700110 if (is_empty_eth_addr(addr)) return 0;
Jakub Pawlowskia83ac122017-06-15 11:53:33 -0700111 return addr.address[0] & 1 ? 0 : 1; /* Cannot be multicasting address */
The Android Open Source Project5738f832012-12-12 16:00:35 -0800112}
113
The Android Open Source Project5738f832012-12-12 16:00:35 -0800114#endif