Blame tools/ubcsp.h

Packit 34410b
/*
Packit 34410b
 *
Packit 34410b
 *  BlueZ - Bluetooth protocol stack for Linux
Packit 34410b
 *
Packit 34410b
 *  Copyright (C) 2000-2005  CSR Ltd.
Packit 34410b
 *
Packit 34410b
 *
Packit 34410b
 *  Permission is hereby granted, free of charge, to any person obtaining
Packit 34410b
 *  a copy of this software and associated documentation files (the
Packit 34410b
 *  "Software"), to deal in the Software without restriction, including
Packit 34410b
 *  without limitation the rights to use, copy, modify, merge, publish,
Packit 34410b
 *  distribute, sublicense, and/or sell copies of the Software, and to
Packit 34410b
 *  permit persons to whom the Software is furnished to do so, subject to
Packit 34410b
 *  the following conditions:
Packit 34410b
 *
Packit 34410b
 *  The above copyright notice and this permission notice shall be included
Packit 34410b
 *  in all copies or substantial portions of the Software.
Packit 34410b
 *
Packit 34410b
 *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
Packit 34410b
 *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
Packit 34410b
 *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
Packit 34410b
 *  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
Packit 34410b
 *  CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
Packit 34410b
 *  TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
Packit 34410b
 *  SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Packit 34410b
 *
Packit 34410b
 */
Packit 34410b

Packit 34410b
#ifndef UBCSP_INCLUDE_H
Packit 34410b
#define UBCSP_INCLUDE_H
Packit 34410b

Packit 34410b
/*****************************************************************************/
Packit 34410b
/*****************************************************************************/
Packit 34410b
/*****************************************************************************/
Packit 34410b
/**                                                                         **/
Packit 34410b
/** ubcsp.h                                                                 **/
Packit 34410b
/**                                                                         **/
Packit 34410b
/** MicroBCSP - a very low cost implementation of the BCSP protocol         **/
Packit 34410b
/**                                                                         **/
Packit 34410b
/*****************************************************************************/
Packit 34410b

Packit 34410b
/* If we wish to use CRC's, then change 0 to 1 in the next line */
Packit 34410b
#define UBCSP_CRC 1
Packit 34410b

Packit 34410b
/* Define some basic types - change these for your architecture */
Packit 34410b
typedef unsigned char uint8;
Packit 34410b
typedef unsigned short uint16;
Packit 34410b
typedef unsigned int uint32;
Packit 34410b
typedef signed char int8;
Packit 34410b
typedef signed short int16;
Packit 34410b
typedef signed int int32;
Packit 34410b

Packit 34410b
/* The defines below require a printf function to be available */
Packit 34410b

Packit 34410b
/* Do we want to show packet errors in debug output */
Packit 34410b
#define SHOW_PACKET_ERRORS	0
Packit 34410b

Packit 34410b
/* Do we want to show Link Establishment State transitions in debug output */
Packit 34410b
#define SHOW_LE_STATES		0
Packit 34410b

Packit 34410b
/*****************************************************************************/
Packit 34410b
/**                                                                         **/
Packit 34410b
/** ubcsp_packet                                                            **/
Packit 34410b
/**                                                                         **/
Packit 34410b
/** This is description of a bcsp packet for the upper layer                **/
Packit 34410b
/**                                                                         **/
Packit 34410b
/*****************************************************************************/
Packit 34410b

Packit 34410b
struct ubcsp_packet
Packit 34410b
{
Packit 34410b
	uint8 channel;		/* Which Channel this packet is to/from */
Packit 34410b
	uint8 reliable;		/* Is this packet reliable */
Packit 34410b
	uint8 use_crc;		/* Does this packet use CRC data protection */
Packit 34410b
	uint16 length;		/* What is the length of the payload data */
Packit 34410b
	uint8 *payload;		/* The payload data itself - size of length */
Packit 34410b
};
Packit 34410b

Packit 34410b
/*****************************************************************************/
Packit 34410b
/**                                                                         **/
Packit 34410b
/** ubcsp_configuration                                                     **/
Packit 34410b
/**                                                                         **/
Packit 34410b
/** This is the main configuration of the ubcsp engine                      **/
Packit 34410b
/** All state variables are stored in this structure                        **/
Packit 34410b
/**                                                                         **/
Packit 34410b
/*****************************************************************************/
Packit 34410b

Packit 34410b
enum ubcsp_link_establishment_state
Packit 34410b
{
Packit 34410b
	ubcsp_le_uninitialized,
Packit 34410b
	ubcsp_le_initialized,
Packit 34410b
	ubcsp_le_active
Packit 34410b
};
Packit 34410b

Packit 34410b
enum ubcsp_link_establishment_packet
Packit 34410b
{
Packit 34410b
	ubcsp_le_sync,
Packit 34410b
	ubcsp_le_sync_resp,
Packit 34410b
	ubcsp_le_conf,
Packit 34410b
	ubcsp_le_conf_resp,
Packit 34410b
	ubcsp_le_none
Packit 34410b
};
Packit 34410b

Packit 34410b
struct ubcsp_configuration
Packit 34410b
{
Packit 34410b
	uint8 link_establishment_state;
Packit 34410b
	uint8 link_establishment_resp;
Packit 34410b
	uint8 link_establishment_packet;
Packit 34410b

Packit 34410b
	uint8 sequence_number:3;
Packit 34410b
	uint8 ack_number:3;
Packit 34410b
	uint8 send_ack;
Packit 34410b
	struct ubcsp_packet *send_packet;
Packit 34410b
	struct ubcsp_packet *receive_packet;
Packit 34410b

Packit 34410b
	uint8 receive_header_checksum;
Packit 34410b
	uint8 receive_slip_escape;
Packit 34410b
	int32 receive_index;
Packit 34410b

Packit 34410b
	uint8 send_header_checksum;
Packit 34410b
#ifdef UBCSP_CRC
Packit 34410b
	uint8 need_send_crc;
Packit 34410b
	uint16 send_crc;
Packit 34410b
#endif
Packit 34410b
	uint8 send_slip_escape;
Packit 34410b

Packit 34410b
	uint8 *send_ptr;
Packit 34410b
	int32 send_size;
Packit 34410b
	uint8 *next_send_ptr;
Packit 34410b
	int32 next_send_size;
Packit 34410b

Packit 34410b
	int8 delay;
Packit 34410b
};
Packit 34410b

Packit 34410b
/*****************************************************************************/
Packit 34410b
/**                                                                         **/
Packit 34410b
/** ubcsp_poll sets activity from an OR of these flags                      **/
Packit 34410b
/**                                                                         **/
Packit 34410b
/*****************************************************************************/
Packit 34410b

Packit 34410b
#define UBCSP_PACKET_SENT 0x01
Packit 34410b
#define UBCSP_PACKET_RECEIVED 0x02
Packit 34410b
#define UBCSP_PEER_RESET 0x04
Packit 34410b
#define UBCSP_PACKET_ACK 0x08
Packit 34410b

Packit 34410b
/*****************************************************************************/
Packit 34410b
/**                                                                         **/
Packit 34410b
/** This is the functional interface for ucbsp                              **/
Packit 34410b
/**                                                                         **/
Packit 34410b
/*****************************************************************************/
Packit 34410b

Packit 34410b
void ubcsp_initialize (void);
Packit 34410b
void ubcsp_send_packet (struct ubcsp_packet *send_packet);
Packit 34410b
void ubcsp_receive_packet (struct ubcsp_packet *receive_packet);
Packit 34410b
uint8 ubcsp_poll (uint8 *activity);
Packit 34410b

Packit 34410b
/*****************************************************************************/
Packit 34410b
/**                                                                         **/
Packit 34410b
/** Slip Escape Values                                                      **/
Packit 34410b
/**                                                                         **/
Packit 34410b
/*****************************************************************************/
Packit 34410b

Packit 34410b
#define SLIP_FRAME 0xC0
Packit 34410b
#define SLIP_ESCAPE 0xDB
Packit 34410b
#define SLIP_ESCAPE_FRAME 0xDC
Packit 34410b
#define SLIP_ESCAPE_ESCAPE 0xDD
Packit 34410b

Packit 34410b
/*****************************************************************************/
Packit 34410b
/*****************************************************************************/
Packit 34410b
/*****************************************************************************/
Packit 34410b

Packit 34410b
/*****************************************************************************/
Packit 34410b
/**                                                                         **/
Packit 34410b
/** These functions need to be linked into your system                      **/
Packit 34410b
/**                                                                         **/
Packit 34410b
/*****************************************************************************/
Packit 34410b

Packit 34410b
/*****************************************************************************/
Packit 34410b
/**                                                                         **/
Packit 34410b
/** put_uart outputs a single octet over the UART Tx line                   **/
Packit 34410b
/**                                                                         **/
Packit 34410b
/*****************************************************************************/
Packit 34410b

Packit 34410b
extern void put_uart (uint8);
Packit 34410b

Packit 34410b
/*****************************************************************************/
Packit 34410b
/**                                                                         **/
Packit 34410b
/** get_uart receives a single octet over the UART Rx line                  **/
Packit 34410b
/** if no octet is available, then this returns 0                           **/
Packit 34410b
/** if an octet was read, then this is returned in the argument and         **/
Packit 34410b
/**   the function returns 1                                                **/
Packit 34410b
/**                                                                         **/
Packit 34410b
/*****************************************************************************/
Packit 34410b

Packit 34410b
extern uint8 get_uart (uint8 *);
Packit 34410b

Packit 34410b
/*****************************************************************************/
Packit 34410b
/**                                                                         **/
Packit 34410b
/** These defines should be changed to your systems concept of 100ms        **/
Packit 34410b
/**                                                                         **/
Packit 34410b
/*****************************************************************************/
Packit 34410b

Packit 34410b
#define UBCSP_POLL_TIME_IMMEDIATE   0
Packit 34410b
#define UBCSP_POLL_TIME_DELAY       25
Packit 34410b

Packit 34410b
/*****************************************************************************/
Packit 34410b
/*****************************************************************************/
Packit 34410b
/*****************************************************************************/
Packit 34410b
#endif