1/****************************************************************************** 2 * 3 * Copyright (C) 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 BNEP definitions 22 * 23 ******************************************************************************/ 24 25#ifndef BNEP_INT_H 26#define BNEP_INT_H 27 28#include "bnep_api.h" 29#include "bt_common.h" 30#include "bt_target.h" 31#include "btm_int.h" 32#include "btu.h" 33 34/* BNEP frame types 35*/ 36#define BNEP_FRAME_GENERAL_ETHERNET 0x00 37#define BNEP_FRAME_CONTROL 0x01 38#define BNEP_FRAME_COMPRESSED_ETHERNET 0x02 39#define BNEP_FRAME_COMPRESSED_ETHERNET_SRC_ONLY 0x03 40#define BNEP_FRAME_COMPRESSED_ETHERNET_DEST_ONLY 0x04 41 42/* BNEP filter control message types 43*/ 44#define BNEP_CONTROL_COMMAND_NOT_UNDERSTOOD 0x00 45#define BNEP_SETUP_CONNECTION_REQUEST_MSG 0x01 46#define BNEP_SETUP_CONNECTION_RESPONSE_MSG 0x02 47#define BNEP_FILTER_NET_TYPE_SET_MSG 0x03 48#define BNEP_FILTER_NET_TYPE_RESPONSE_MSG 0x04 49#define BNEP_FILTER_MULTI_ADDR_SET_MSG 0x05 50#define BNEP_FILTER_MULTI_ADDR_RESPONSE_MSG 0x06 51 52/* BNEP header extension types 53*/ 54#define BNEP_EXTENSION_FILTER_CONTROL 0x00 55 56/* BNEP Setup Connection response codes 57*/ 58#define BNEP_SETUP_CONN_OK 0x0000 59#define BNEP_SETUP_INVALID_DEST_UUID 0x0001 60#define BNEP_SETUP_INVALID_SRC_UUID 0x0002 61#define BNEP_SETUP_INVALID_UUID_SIZE 0x0003 62#define BNEP_SETUP_CONN_NOT_ALLOWED 0x0004 63 64/* BNEP filter control response codes 65*/ 66#define BNEP_FILTER_CRL_OK 0x0000 67#define BNEP_FILTER_CRL_UNSUPPORTED 0x0001 68#define BNEP_FILTER_CRL_BAD_RANGE 0x0002 69#define BNEP_FILTER_CRL_MAX_REACHED 0x0003 70#define BNEP_FILTER_CRL_SECURITY_ERR 0x0004 71 72/* 802.1p protocol packet will have actual protocol field in side the payload */ 73#define BNEP_802_1_P_PROTOCOL 0x8100 74 75/* Timeout definitions. */ 76/* Connection related timeout */ 77#define BNEP_CONN_TIMEOUT_MS (20 * 1000) 78/* host response timeout */ 79#define BNEP_HOST_TIMEOUT_MS (200 * 1000) 80#define BNEP_FILTER_SET_TIMEOUT_MS (10 * 1000) 81 82/* Define the Out-Flow default values. */ 83#define BNEP_OFLOW_QOS_FLAG 0 84#define BNEP_OFLOW_SERV_TYPE 0 85#define BNEP_OFLOW_TOKEN_RATE 0 86#define BNEP_OFLOW_TOKEN_BUCKET_SIZE 0 87#define BNEP_OFLOW_PEAK_BANDWIDTH 0 88#define BNEP_OFLOW_LATENCY 0 89#define BNEP_OFLOW_DELAY_VARIATION 0 90 91/* Define the In-Flow default values. */ 92#define BNEP_IFLOW_QOS_FLAG 0 93#define BNEP_IFLOW_SERV_TYPE 0 94#define BNEP_IFLOW_TOKEN_RATE 0 95#define BNEP_IFLOW_TOKEN_BUCKET_SIZE 0 96#define BNEP_IFLOW_PEAK_BANDWIDTH 0 97#define BNEP_IFLOW_LATENCY 0 98#define BNEP_IFLOW_DELAY_VARIATION 0 99 100#define BNEP_FLUSH_TO 0xFFFF 101 102#define BNEP_MAX_RETRANSMITS 3 103 104/* Define the BNEP Connection Control Block 105*/ 106typedef struct { 107#define BNEP_STATE_IDLE 0 108#define BNEP_STATE_CONN_START 1 109#define BNEP_STATE_CFG_SETUP 2 110#define BNEP_STATE_CONN_SETUP 3 111#define BNEP_STATE_SEC_CHECKING 4 112#define BNEP_STATE_SETUP_RCVD 5 113#define BNEP_STATE_CONNECTED 6 114 uint8_t con_state; 115 116#define BNEP_FLAGS_IS_ORIG 0x01 117#define BNEP_FLAGS_HIS_CFG_DONE 0x02 118#define BNEP_FLAGS_MY_CFG_DONE 0x04 119#define BNEP_FLAGS_L2CAP_CONGESTED 0x08 120#define BNEP_FLAGS_FILTER_RESP_PEND 0x10 121#define BNEP_FLAGS_MULTI_RESP_PEND 0x20 122#define BNEP_FLAGS_SETUP_RCVD 0x40 123#define BNEP_FLAGS_CONN_COMPLETED 0x80 124 uint8_t con_flags; 125 BT_HDR* p_pending_data; 126 127 uint16_t l2cap_cid; 128 BD_ADDR rem_bda; 129 uint16_t rem_mtu_size; 130 alarm_t* conn_timer; 131 fixed_queue_t* xmit_q; 132 133 uint16_t sent_num_filters; 134 uint16_t sent_prot_filter_start[BNEP_MAX_PROT_FILTERS]; 135 uint16_t sent_prot_filter_end[BNEP_MAX_PROT_FILTERS]; 136 137 uint16_t sent_mcast_filters; 138 BD_ADDR sent_mcast_filter_start[BNEP_MAX_MULTI_FILTERS]; 139 BD_ADDR sent_mcast_filter_end[BNEP_MAX_MULTI_FILTERS]; 140 141 uint16_t rcvd_num_filters; 142 uint16_t rcvd_prot_filter_start[BNEP_MAX_PROT_FILTERS]; 143 uint16_t rcvd_prot_filter_end[BNEP_MAX_PROT_FILTERS]; 144 145 uint16_t rcvd_mcast_filters; 146 BD_ADDR rcvd_mcast_filter_start[BNEP_MAX_MULTI_FILTERS]; 147 BD_ADDR rcvd_mcast_filter_end[BNEP_MAX_MULTI_FILTERS]; 148 149 uint16_t bad_pkts_rcvd; 150 uint8_t re_transmits; 151 uint16_t handle; 152 tBT_UUID prv_src_uuid; 153 tBT_UUID prv_dst_uuid; 154 tBT_UUID src_uuid; 155 tBT_UUID dst_uuid; 156 157} tBNEP_CONN; 158 159/* The main BNEP control block 160*/ 161typedef struct { 162 tL2CAP_CFG_INFO l2cap_my_cfg; /* My L2CAP config */ 163 tBNEP_CONN bcb[BNEP_MAX_CONNECTIONS]; 164 165 tBNEP_CONNECT_IND_CB* p_conn_ind_cb; 166 tBNEP_CONN_STATE_CB* p_conn_state_cb; 167 tBNEP_DATA_IND_CB* p_data_ind_cb; 168 tBNEP_DATA_BUF_CB* p_data_buf_cb; 169 tBNEP_FILTER_IND_CB* p_filter_ind_cb; 170 tBNEP_MFILTER_IND_CB* p_mfilter_ind_cb; 171 tBNEP_TX_DATA_FLOW_CB* p_tx_data_flow_cb; 172 173 tL2CAP_APPL_INFO reg_info; 174 175 bool profile_registered; /* true when we got our BD addr */ 176 uint8_t trace_level; 177 178} tBNEP_CB; 179 180/* Global BNEP data 181*/ 182extern tBNEP_CB bnep_cb; 183 184/* Functions provided by bnep_main.cc 185*/ 186extern tBNEP_RESULT bnep_register_with_l2cap(void); 187extern void bnep_disconnect(tBNEP_CONN* p_bcb, uint16_t reason); 188extern tBNEP_CONN* bnep_conn_originate(uint8_t* p_bd_addr); 189extern void bnep_conn_timer_timeout(void* data); 190extern void bnep_connected(tBNEP_CONN* p_bcb); 191 192/* Functions provided by bnep_utils.cc 193*/ 194extern tBNEP_CONN* bnepu_find_bcb_by_cid(uint16_t cid); 195extern tBNEP_CONN* bnepu_find_bcb_by_bd_addr(uint8_t* p_bda); 196extern tBNEP_CONN* bnepu_allocate_bcb(BD_ADDR p_rem_bda); 197extern void bnepu_release_bcb(tBNEP_CONN* p_bcb); 198extern void bnepu_send_peer_our_filters(tBNEP_CONN* p_bcb); 199extern void bnepu_send_peer_our_multi_filters(tBNEP_CONN* p_bcb); 200extern bool bnepu_does_dest_support_prot(tBNEP_CONN* p_bcb, uint16_t protocol); 201extern void bnepu_build_bnep_hdr(tBNEP_CONN* p_bcb, BT_HDR* p_buf, 202 uint16_t protocol, uint8_t* p_src_addr, 203 uint8_t* p_dest_addr, bool ext_bit); 204extern void test_bnepu_build_bnep_hdr(tBNEP_CONN* p_bcb, BT_HDR* p_buf, 205 uint16_t protocol, uint8_t* p_src_addr, 206 uint8_t* p_dest_addr, uint8_t type); 207 208extern tBNEP_CONN* bnepu_get_route_to_dest(uint8_t* p_bda); 209extern void bnepu_check_send_packet(tBNEP_CONN* p_bcb, BT_HDR* p_buf); 210extern void bnep_send_command_not_understood(tBNEP_CONN* p_bcb, 211 uint8_t cmd_code); 212extern void bnepu_process_peer_filter_set(tBNEP_CONN* p_bcb, uint8_t* p_filters, 213 uint16_t len); 214extern void bnepu_process_peer_filter_rsp(tBNEP_CONN* p_bcb, uint8_t* p_data); 215extern void bnepu_process_multicast_filter_rsp(tBNEP_CONN* p_bcb, 216 uint8_t* p_data); 217extern void bnep_send_conn_req(tBNEP_CONN* p_bcb); 218extern void bnep_send_conn_responce(tBNEP_CONN* p_bcb, uint16_t resp_code); 219extern void bnep_process_setup_conn_req(tBNEP_CONN* p_bcb, uint8_t* p_setup, 220 uint8_t len); 221extern void bnep_process_setup_conn_responce(tBNEP_CONN* p_bcb, 222 uint8_t* p_setup); 223extern uint8_t* bnep_process_control_packet(tBNEP_CONN* p_bcb, uint8_t* p, 224 uint16_t* len, bool is_ext); 225extern void bnep_sec_check_complete(BD_ADDR bd_addr, tBT_TRANSPORT trasnport, 226 void* p_ref_data, uint8_t result); 227extern tBNEP_RESULT bnep_is_packet_allowed(tBNEP_CONN* p_bcb, 228 BD_ADDR p_dest_addr, 229 uint16_t protocol, 230 bool fw_ext_present, 231 uint8_t* p_data); 232extern uint32_t bnep_get_uuid32(tBT_UUID* src_uuid); 233 234#endif 235