mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-02-05 09:40:00 +00:00
Added bnep.c bnep.h, still under development, may not yet compile
This commit is contained in:
parent
52575d0137
commit
66b319ed3a
1191
src/bnep.c
Normal file
1191
src/bnep.c
Normal file
File diff suppressed because it is too large
Load Diff
200
src/bnep.h
Normal file
200
src/bnep.h
Normal file
@ -0,0 +1,200 @@
|
||||
/*
|
||||
* Copyright (C) 2014 by Ole Reinhardt <ole.reinhardt@kernelconcepts.de>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the copyright holders nor the names of
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
* 4. Any redistribution, use, or modification is done solely for
|
||||
* personal benefit and not for any commercial purpose or for
|
||||
* monetary gain.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
|
||||
* THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* Please inquire about commercial licensing options at btstack@ringwald.ch
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* BNEP.h
|
||||
*/
|
||||
|
||||
#ifndef __BNEP_H
|
||||
#define __BNEP_H
|
||||
|
||||
#include <btstack/btstack.h>
|
||||
#include <btstack/utils.h>
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#if defined __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define BNEP_MTU_MIN 1691
|
||||
|
||||
#define MAX_BNEP_NETFILTER 8
|
||||
#define MAX_BNEP_MULTICAST_FILTER 8
|
||||
|
||||
#define BNEP_EXT_FLAG 0x80
|
||||
#define BNEP_TYPE_MASK 0x7F
|
||||
#define BNEP_TYPE(header) ((header) & BNEP_TYPE_MASK)
|
||||
#define BNEP_HEADER_HAS_EXT(x) (((x) & BNEP_EXT_FLAG) == BNEP_EXT_FLAG)
|
||||
|
||||
/* BNEP UUIDs */
|
||||
#define BNEP_UUID_PANU 0x1115
|
||||
#define BNEP_UUID_NAP 0x1116
|
||||
#define BNEP_UUID_GN 0x1117
|
||||
|
||||
/* BNEP packet types */
|
||||
#define BNEP_PKT_TYPE_GENERAL_ETHERNET 0x00
|
||||
#define BNEP_PKT_TYPE_CONTROL 0x01
|
||||
#define BNEP_PKT_TYPE_COMPRESSED_ETHERNET 0x02
|
||||
#define BNEP_PKT_TYPE_COMPRESSED_ETHERNET_SOURCE_ONLY 0x03
|
||||
#define BNEP_PKT_TYPE_COMPRESSED_ETHERNET_DEST_ONLY 0x04
|
||||
|
||||
/* BNEP control types */
|
||||
#define BNEP_CONTROL_TYPE_COMMAND_NOT_UNDERSTOOD 0x00
|
||||
#define BNEP_CONTROL_TYPE_SETUP_CONNECTION_REQUEST 0x01
|
||||
#define BNEP_CONTROL_TYPE_SETUP_CONNECTION_RESPONSE 0x02
|
||||
#define BNEP_CONTROL_TYPE_FILTER_NET_TYPE_SET 0x03
|
||||
#define BNEP_CONTROL_TYPE_FILTER_NET_TYPE_RESPONSE 0x04
|
||||
#define BNEP_CONTROL_TYPE_FILTER_MULTI_ADDR_SET 0x05
|
||||
#define BNEP_CONTROL_TYPE_FILTER_MULTI_ADDR_RESPONSE 0x06
|
||||
|
||||
/* BNEP extension header types */
|
||||
#define BNEP_EXT_HEADER_TYPE_EXTENSION_CONTROL 0x00
|
||||
|
||||
/* BNEP setup response codes */
|
||||
#define BNEP_RESP_SETUP_SUCCESS 0x0000
|
||||
#define BNEP_RESP_SETUP_INVALID_DEST_UUID 0x0001
|
||||
#define BNEP_RESP_SETUP_INVALID_SOURCE_UUID 0x0002
|
||||
#define BNEP_RESP_SETUP_INVALID_SERVICE_UUID_SIZE 0x0003
|
||||
#define BNEP_RESP_SETUP_CONNECTION_NOT_ALLOWED 0x0004
|
||||
|
||||
/* BNEP filter response codes */
|
||||
#define BNEP_RESP_FILTER_SUCCESS 0x0000
|
||||
#define BNEP_RESP_FILTER_UNSUPPORTED_REQUEST 0x0001
|
||||
#define BNEP_RESP_FILTER_ERR_INVALID_RANGE 0x0002
|
||||
#define BNEP_RESP_FILTER_ERR_TOO_MANY_FILTERS 0x0003
|
||||
#define BNEP_RESP_FILTER_ERR_SECURITY 0x0004
|
||||
|
||||
typedef enum {
|
||||
BNEP_CHANNEL_STATE_CLOSED = 1,
|
||||
BNEP_CHANNEL_STATE_INIT,
|
||||
BNEP_CHANNEL_STATE_WAIT_FOR_CONNECTION_REQUEST,
|
||||
BNEP_CHANNEL_STATE_WAIT_FOR_CONNECTION_RESPONSE,
|
||||
BNEP_CHANNEL_STATE_CONNECTED,
|
||||
} BNEP_CHANNEL_STATE;
|
||||
|
||||
typedef enum {
|
||||
BNEP_EVT_RCVD_CON_REQ = 1,
|
||||
BNEP_EVT_RCVD_CON_RESP,
|
||||
BNEP_EVT_RCVD_FILTER_SET_TYPE_REQ,
|
||||
BNEP_EVT_RCVD_FILTER_SET_TYPE_RESP,
|
||||
BNEP_EVT_RCVD_MULTI_ADDR_SET,
|
||||
BNEP_EVT_RCVD_MULTI_ADDR_RESP,
|
||||
} BNEP_EVENT;
|
||||
|
||||
/* network protocol type filter */
|
||||
typedef struct {
|
||||
uint16_t range_start;
|
||||
uint16_t range_end;
|
||||
} bnep_net_filter;
|
||||
|
||||
/* multicast address filter */
|
||||
struct mfilter {
|
||||
uint8_t addr_start[ETHER_ADDR_LEN];
|
||||
uint8_t addr_end[ETHER_ADDR_LEN];
|
||||
} bnep_multi_filter;
|
||||
|
||||
|
||||
// info regarding multiplexer
|
||||
// note: spec mandates single multplexer per device combination
|
||||
typedef struct {
|
||||
// linked list - assert: first field
|
||||
linked_item_t item;
|
||||
|
||||
BNEP_CHANNEL_STATE state;
|
||||
|
||||
uint16_t max_frame_size; // incomming max. frame size
|
||||
void *connection; // client connection
|
||||
bd_addr_t remote_addr; // remote device address
|
||||
uint16_t l2cap_cid; // l2cap channel id
|
||||
hci_con_handle_t con_handle; // hci connection handle
|
||||
|
||||
uint16_t uuid_source; // Source UUID
|
||||
uint16_t uuid_dest; // Destination UUID
|
||||
|
||||
bnep_net_filter net_filter[MAX_BNEP_NETFILTER]; // network protocol filter, define fixed size for now
|
||||
uint16_t net_filter_count;
|
||||
|
||||
bnep_multi_filter multicast_filter[MAX_BNEP_MULTICAST_FILTER]; // multicast address filter, define fixed size for now
|
||||
uint16_t multicast_filter_count;
|
||||
|
||||
// l2cap packet handler
|
||||
btstack_packet_handler_t packet_handler;
|
||||
|
||||
} bnep_channel_t;
|
||||
|
||||
/* Internal BNEP service descriptor */
|
||||
typedef struct {
|
||||
linked_item_t item; // linked list - assert: first field
|
||||
void *connection; // client connection
|
||||
uint16_t service_uuid; // Service class: PANU, NAP, GN
|
||||
|
||||
// internal connection
|
||||
btstack_packet_handler_t packet_handler;
|
||||
} bnep_service_t;
|
||||
|
||||
|
||||
void bnep_packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size);
|
||||
|
||||
/** Embedded API **/
|
||||
|
||||
/* Set up BNEP. */
|
||||
void bnep_init(void);
|
||||
|
||||
/* Set security level required for incoming connections, need to be called before registering services */
|
||||
void bnep_set_required_security_level(gap_security_level_t security_level);
|
||||
|
||||
/* Register packet handler. */
|
||||
void bnep_register_packet_handler(void (*handler)(void * connection, uint8_t packet_type,
|
||||
uint16_t channel, uint8_t *packet, uint16_t size));
|
||||
|
||||
// Creates BNEP connection (channel) to a given server on a remote device with baseband address. A new baseband connection will be initiated if necessary.
|
||||
void bnep_create_channel_internal(void * connection, bd_addr_t *addr, uint8_t channel);
|
||||
|
||||
// Disconencts BNEP channel with given identifier.
|
||||
void bnep_disconnect(uint16_t bnep_cid);
|
||||
|
||||
// Registers BNEP service, set a maximum frame size and assigns a packet handler. On embedded systems, use NULL for connection parameter.
|
||||
void bnep_register_service(void * connection, uint16_t service_uuid, uint16_t max_frame_size);
|
||||
|
||||
// Unregister BNEP service.
|
||||
void bnep_unregister_service_internal(uint8_t service_channel);
|
||||
|
||||
#if defined __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // __BNEP_H
|
Loading…
x
Reference in New Issue
Block a user