800*320工程文件+初始demo提交

This commit is contained in:
2024-03-07 16:46:43 +08:00
parent 33e6eb45b3
commit 70ec3005bb
3306 changed files with 3374364 additions and 2563 deletions

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,39 @@
/*
****************************************************************************************
*
* @file app_error.h
* @version v1.0
* @brief error code of app layer
* @attention
* Copyright (C) 2023 Freqchip. \n
* All rights reserved. \n
*
*
****************************************************************************************
*/
#ifndef __APP_ERROR_H_
#define __APP_ERROR_H_
typedef enum app_error app_err_t;
enum app_error
{
/// no error
APP_ERR_NO_ERR = 0x00,
/// the input parameter is incorrect
APP_ERR_INVAILD_PARAM = 0x01,
/// the specified conidx has no device connection
APP_ERR_DEVICE_NOT_CONNECTED = 0x02,
// ----------------------------------------------------
// ----------------- GATT API Error -------------------
// ----------------------------------------------------
/// invaild client_id or service_id
APP_ERR_INVAILD_ID = 0x10,
/// GAP AND GATT service is deleted
APP_ERR_SVC_IS_DELETED = 0x11,
/// client handles group is empty
APP_ERR_CLIENT_HDL_IS_EMPTY = 0x12,
};
#endif

View File

@ -0,0 +1,127 @@
/****************************************************************************
*
* File:
* $Id: atconfig.h 1378 2009-04-14 23:22:21Z brentk $
* $Product: iAnywhere Hands-Free SDK version 2.x $
* $Revision: 1378 $
*
* Description: This file contains an AT Command Processor configuration
* constants.
*
* Copyright 2002-2005 Extended Systems, Inc.
* Portions copyright 2005-2009 iAnywhere Solutions, Inc.
* All rights reserved. All unpublished rights reserved.
*
* Unpublished Confidential Information of iAnywhere Solutions, Inc.
* Do Not Disclose.
*
* No part of this work may be used or reproduced in any form or by any
* means, or stored in a database or retrieval system, without prior written
* permission of iAnywhere Solutions, Inc.
*
* Use of this work is governed by a license granted by iAnywhere Solutions,
* Inc. This work contains confidential and proprietary information of
* iAnywhere Solutions, Inc. which is protected by copyright, trade secret,
* trademark and other intellectual property rights.
*
****************************************************************************/
#ifndef __ATCONFIG_H
#define __ATCONFIG_H
#include "config.h"
/*----------------------------------------------------------------------------
*
*/
#ifndef AT_HEADSET
#define AT_HEADSET XA_DISABLED
#endif
/*----------------------------------------------------------------------------
*
*/
#ifndef AT_HANDSFREE
#define AT_HANDSFREE XA_DISABLED
#endif
#if AT_HANDSFREE == XA_ENABLED
/* Headset commands must be included when using handsfree. */
#undef AT_HEADSET
#define AT_HEADSET XA_ENABLED
#endif
/*----------------------------------------------------------------------------
*
*/
#ifndef AT_PHONEBOOK
#define AT_PHONEBOOK XA_DISABLED
#endif
/*----------------------------------------------------------------------------
*
*/
#ifndef AT_SMS
#define AT_SMS XA_DISABLED
#endif
/*----------------------------------------------------------------------------
*
*/
#ifndef AT_DUN
#define AT_DUN XA_DISABLED
#endif
/*----------------------------------------------------------------------------
*
*/
#ifndef AT_ROLE_TERMINAL
#define AT_ROLE_TERMINAL XA_DISABLED
#endif
/*----------------------------------------------------------------------------
*
*/
#ifndef AT_ROLE_MOBILE
#define AT_ROLE_MOBILE XA_DISABLED
#endif
/*----------------------------------------------------------------------------
*
*/
#ifndef AT_MAX_PARMS
#define AT_MAX_PARMS 45
#endif
#if (AT_MAX_PARMS < 16) || (AT_MAX_PARMS > 255)
#error "AT_MAX_PARMS must be between 16 and 255."
#endif
/*----------------------------------------------------------------------------
* This is maximum the number of indicators that are supported by the Hands
* Free code. This value defaults to 20, but it can be changed to something
* less to save a few bytes by defining it in the overide.h file instead.
* This value must never be greater thatn 20, as indicated by the Hands Free
* specification Errata 2742. Note that 20 is NOT the maximum number of
* indicators that can be reported by a cell network to an audio gateway.
* However, it is the maximum number that can be reported over a Bluetooth
* Handsfree connection. If the cellular network has more than 20
* indicators, then the audio gateway will have to selectively limit what it
* reports to the Hands Free Unit.
*/
#ifndef AT_MAX_INDICATORS
#define AT_MAX_INDICATORS 20
#endif
#if (20 < AT_MAX_INDICATORS)
#error "HF Spec Errata 2742 violation: AT_MAX_INDICATORS must be less than or equal to 20."
#endif
#if (1 > AT_MAX_INDICATORS)
#error "AT_MAX_INDICATORS must be greater than 0."
#endif
#endif /* __ATCONFIG_H */

View File

@ -0,0 +1,66 @@
#ifndef __ATP_H
#define __ATP_H
/** This result acknowledges successful acceptance of a command. There are
* no parameters with this command.
*/
#define AT_OK 0x0000
/** This result indicates that the received command was not accepted. There
* are no parameters with this command.
*/
#define AT_ERROR 0x0001
/** This unsolicited result indicates an incoming call signal from network.
* There are no parameters with this command.
*/
#define AT_RING 0x0002
/** This result indicates that the received command was not accepted. The
* "error" parameter is used with this command.
*/
#define AT_EXTENDED_ERROR 0x0003
/** This command is used to enable or disable extended error reporting. The
* "error" parameter is used with this command.
*/
#define AT_SET_ERROR_MODE 0x0004
/** This command informs the mobile equipment of the character set used by
* the terminal equipment. The "charSet" parameter is used with this
* command.
*/
#define AT_SELECT_CHARACTER_SET 0x0005
/** This result indicates that the call could not be established or the
* connection was terminated. There are no parameters with this command.
*/
#define AT_NO_CARRIER 0x0006
/** This result indicates that the called party is busy. There are no
* parameters with this command.
*/
#define AT_BUSY 0x0007
/** This result indicates connection completion on timeout. There are no
* parameters with this command.
*/
#define AT_NO_ANSWER 0x0008
/** This result indicates that calls to the number are temporarily
* forbidden. There are no parameters with this command.
*/
#define AT_DELAYED 0x0009
/** This result indicates that calls to the number are forbidden until a
* manual reset. There are no parameters with this command.
*/
#define AT_BLACKLISTED 0x000A
/** This indicates that the data will be sent as 'raw' AT data. The
* "data" parameter is used with this response.
*/
#define AT_RAW 0x000B
#endif

View File

@ -0,0 +1,643 @@
#ifndef __AVCTP_API_H_
#define __AVCTP_API_H_
#include "btconfig.h"
#include "bt_types.h"
#include "me_api.h"
/*---------------------------------------------------------------------------
* AVCTP API layer
*
* The Audio/Video Remote Control Transport Protocol (AVCTP) defines
* procedures for exchanging 1394 Trade Association AV/C commands between
* Bluetooth enabled Audio/Video devices.
*
* This API is designed to support AV remote control applications using
* the iAnywhere Blue SDK core protocol stack. It provides an API
* for connection management and message handling.
*/
/****************************************************************************
*
* Types
*
****************************************************************************/
/*---------------------------------------------------------------------------
* AvctpEvent type
*
*/
typedef uint8_t AvctpEvent;
/** The transport layer is connected and commands/responses can now
* be exchanged.
*
* During this callback, the 'p.remDev' parameter is valid.
*/
#define AVCTP_EVENT_CONNECT 1
/** A remote device is attempting to connect the transport layer.
* Only the acceptor of the connection is notified. The acceptor must
* call AVCTP_ConnectRsp() to either accept or reject the connection.
*
* During this callback, the 'p.remDev' parameter is valid.
*/
#define AVCTP_EVENT_CONNECT_IND 2
/** The transport layer been disconnected.
*
* During this callback, the 'p.remDev' parameter is valid.
*/
#define AVCTP_EVENT_DISCONNECT 3
/** A command was received from the remote AVCTP device (controller).
*
* During this callback, the 'p.cmdFrame' parameter is valid. It contains the
* the AVCTP command header information, including operands. If the "more"
* value is TRUE then this event only signals the first part of the operands.
* Subsequent AVCTP_EVENT_OPERANDS events will follow this event with
* additional operand data.
*/
#define AVCTP_EVENT_COMMAND 4
/** A response was received from the remote AVCTP device (target).
*
* During this callback, the 'p.rspFrame' parameter is valid. It contains the
* the AVCTP response header information, including operands. If the "more"
* value is TRUE then this event only signals the first part of the operands.
* Subsequent AVCTP_EVENT_OPERANDS events will follow this event with
* additional operand data.
*/
#define AVCTP_EVENT_RESPONSE 5
/** The remote device (target) rejected the AVCTP command.
*
* During this callback, the 'p.rspFrame' parameter is valid. It contains the
* the AVCTP reject header information, including operands. If the "more"
* value is TRUE then this event only signals the first part of the operands.
* Subsequent AVCTP_EVENT_OPERANDS events will follow this event with
* additional operand data.
*/
#define AVCTP_EVENT_REJECT 6
/** A command (see AVCTP_SendCommand) or response (see AVCTP_SendResponse)
* has been sent. Memory allocated for the operation can be freed or reused
* after receiving this event.
*
* During this callback, the 'p.cmdFrame' or 'p.rspFrame' parameter associated
* with the sent command or response is valid. In addition, "status" will be
* set to indicate "BT_STATUS_SUCCESS" or "BT_STATUS_FAILED" to indicate
* whether the event was properly delivered.
*/
#define AVCTP_EVENT_TX_DONE 8
/** Additional operand data has been received for the previous
* AVCTP_EVENT_COMMAND or AVCTP_EVENT_RESPONSE.
*
* During this callback, the 'p.cmdFrame' or 'p.rspFrame' parameter associated
* with the received command or response is valid. The "operands" and
* "operandLen" fields indicate the chunk of operands being received for
* the command or response. If the "more" field is set to TRUE, the full
* operand buffer will be received in multiple _OPERANDS events and the
* last operand buffer indicated with the "more" field set to FALSE.
*/
#define AVCTP_EVENT_OPERANDS 9
/* End of AvctpEvent */
#define AVCTP_EVENT_LAST 9
/*---------------------------------------------------------------------------
* AvctpCtype type
*
* This type defines the AV/C ctype (command type) codes.
*/
typedef uint8_t AvctpCtype;
#define AVCTP_CTYPE_CONTROL 0x00
#define AVCTP_CTYPE_STATUS 0x01
#define AVCTP_CTYPE_SPECIFIC_INQUIRY 0x02
#define AVCTP_CTYPE_NOTIFY 0x03
#define AVCTP_CTYPE_GENERAL_INQUIRY 0x04
#define AVCTP_CTYPE_BROWSING 0x80
/* End of AvctpCtype */
/*---------------------------------------------------------------------------
* AvctpResponse type
*
* This type defines the AV/C response codes.
*/
typedef uint8_t AvctpResponse;
#define AVCTP_RESPONSE_NOT_IMPLEMENTED 0x08
#define AVCTP_RESPONSE_ACCEPTED 0x09
#define AVCTP_RESPONSE_REJECTED 0x0A
#define AVCTP_RESPONSE_IN_TRANSITION 0x0B
#define AVCTP_RESPONSE_IMPLEMENTED_STABLE 0x0C
#define AVCTP_RESPONSE_CHANGED 0x0D
#define AVCTP_RESPONSE_INTERIM 0x0F
#define AVCTP_RESPONSE_BROWSING 0x40
/* End of AvctpResponse */
/*---------------------------------------------------------------------------
* AvctpOpcode type
*
* This type defines the AV/C Opcodes.
*/
typedef uint8_t AvctpOpcode;
#define AVCTP_OPCODE_VENDOR_DEPENDENT 0x00
#define AVCTP_OPCODE_UNIT_INFO 0x30
#define AVCTP_OPCODE_SUBUNIT_INFO 0x31
#define AVCTP_OPCODE_PASS_THROUGH 0x7C
/* End of AvctpOpcode */
/* Forward references */
typedef struct _AvctpCallbackParms AvctpCallbackParms;
typedef struct _AvctpChannel AvctpChannel;
typedef struct _AvctpCmdFrame AvctpCmdFrame;
typedef struct _AvctpRspFrame AvctpRspFrame;
/*---------------------------------------------------------------------------
* AvctpCallback type
*
* A function of this type is called to indicate events to the application.
*/
typedef void (*AvctpCallback)(AvctpChannel *chnl, AvctpCallbackParms *Parms);
/* End of AvctpCallback */
/* Forward references */
typedef struct _AvctpConnCallbackParms AvctpConnCallbackParms;
typedef struct _AvctpConn AvctpConn;
/* Conn callback function */
typedef void (*AvctpConnCallback)(AvctpConn *Conn, const AvctpConnCallbackParms *Parms);
/* Conn calback parameters */
struct _AvctpConnCallbackParms {
uint8_t event;
uint16_t dataLen;
BtStatus status;
union {
BtRemoteDevice *remDev;
uint8_t *data;
} ptrs;
};
/* Connection State */
struct _AvctpConn {
uint16_t l2ChannelId;
uint16_t psm;
uint8_t state;
AvctpConnCallback callback;
BtRemoteDevice *remDev;
};
typedef struct _AvtpChannel AvtpChannel;
typedef struct _AvtpCallbackParms AvtpCallbackParms;
/* Channel Manager Callback */
typedef void (*AvtpCallback)(AvtpChannel *chnl, AvtpCallbackParms *Parms);
/* Channel Packet */
typedef struct _AvtpPacket {
ListEntry node;
uint8_t transId;
uint8_t msgType;
uint8_t msgHdrLen;
uint8_t msgHdr[10];
uint8_t txIdSize;
uint16_t txId;
uint16_t txDataLen;
uint8_t *txData;
uint32_t context;
} AvtpPacket;
/* Channel */
struct _AvtpChannel {
uint32_t context;
/* Identifier */
uint16_t rxId;
/* Transmit Packet */
ListEntry avPacketList;
AvtpPacket *curAvPacket;
/* Transmit State */
uint8_t txState;
uint16_t offset;
uint16_t packetSize;
uint8_t txPacketsLeft;
/* Channel Receive State */
uint8_t rxState;
uint8_t rxPacketsLeft;
/* Channel Resources */
BtPacket packet;
uint16_t l2ChannelId;
/* Command Timeout */
uint32_t txTimeout;
EvmTimer txTimer;
/* Channel Callback */
AvtpCallback callback;
};
/* Channel Callback Parameters */
struct _AvtpCallbackParms {
uint8_t event; /* Callback event type */
BtStatus status; /* Transport status */
uint8_t transId; /* Transaction ID */
uint8_t msgType; /* Message type */
uint8_t pktType; /* Packet type */
uint16_t rxId; /* RX ID */
uint8_t packetsLeft; /* Number of packet still to receive */
uint16_t len; /* Length of the current data */
AvtpPacket *packet; /* Pointer to the transmitted packet */
uint8_t *data; /* Pointer to the received data */
};
/****************************************************************************
*
* Data Structures
*
****************************************************************************/
/*---------------------------------------------------------------------------
* AvctpCmdFrame structure
*
* Defines the parameters required for an AVCTP command.
*/
struct _AvctpCmdFrame {
ListEntry node; /* Used internally by AVCTP. */
uint8_t transId; /* Transaction ID */
AvctpCtype ctype; /* 4 bits */
uint8_t subunitType; /* 5 bits */
uint8_t subunitId; /* 3 bits */
AvctpOpcode opcode; /* 8 bits */
uint8_t headerLen; /* Header length */
uint8_t header[6]; /* Header information */
uint16_t operandLen; /* Length of buffer in "operands" */
uint8_t *operands; /* Buffer containing the command data */
int more; /* Indicates whether to expect additional
* frames containing more operand data. */
AvtpPacket avtpPacket; /* For sending over AVTP */
EvmTimer timer; /* Timer for the command */
};
/*---------------------------------------------------------------------------
* AvctpRspFrame structure
*
* Defines the parameters required for an AVCTP response.
*/
struct _AvctpRspFrame {
ListEntry node; /* Used internally by AVCTP. */
uint8_t transId; /* Transaction ID */
AvctpResponse response; /* 4 bits */
uint8_t subunitType; /* 5 bits */
uint8_t subunitId; /* 3 bits */
AvctpOpcode opcode; /* 8 bits */
uint8_t headerLen; /* Header length */
uint8_t header[6]; /* Header information */
uint16_t operandLen; /* Length of buffer in "operands" */
uint8_t *operands; /* Buffer containing the response data */
int more; /* Indicates whether to expect additional
* frames containing more operand data. */
AvtpPacket avtpPacket; /* For sending over AVTP */
EvmTimer padding; /* Timer for the command */
};
/*---------------------------------------------------------------------------
* AvctpChannel structure
*
* Defines the AVCTP channel.
*/
struct _AvctpChannel {
/* === Internal use only === */
ListEntry node;
/* Transmit queue */
ListEntry txQueue;
/* Connection Handle */
AvctpConn conn;
/* Channel Handle */
AvtpChannel avtpChnl;
/* Current Transmitting Command */
void *curCmd;
/* Current Waiting Command ID */
uint8_t curId;
/* Current Transmitting Response */
void *curRsp;
/* Rx Frame */
union {
AvctpCmdFrame cmdFrame;
AvctpRspFrame rspFrame;
} rx;
/* System response packet */
AvtpPacket rspPacket;
/* Transaction ID */
uint8_t txTransId;
/* Receive State */
uint8_t rxState;
/* Transmit State */
uint8_t txState;
/* Application callback function */
AvctpCallback callback;
};
/*---------------------------------------------------------------------------
* AvctpCallbackParms structure
*
* Contains information for the application callback event.
*
*/
struct _AvctpCallbackParms {
/* AVCTP event */
AvctpEvent event;
/* AVCTP channel associated with the event */
AvctpChannel *channel;
/* Status of event (valid only for certain events) */
BtStatus status;
/* Callback parameter object, depending on "event" */
union {
/* Remote device associated with the event */
BtRemoteDevice *remDev;
/* Command frame associated with the event */
AvctpCmdFrame *cmdFrame;
/* Response frame associated with the event */
AvctpRspFrame *rspFrame;
} p;
};
/****************************************************************************
*
* Function Reference
*
****************************************************************************/
#if 0
/*---------------------------------------------------------------------------
* AVCTP_Register()
*
* Registers an application callback to receive AVCTP events. This
* function must be called before any other AVCTP functions.
*
* Parameters:
*
* chnl - Channel structure that receives or initiates connections.
*
* psm - The type of PSM to register (BT_PSM_AVCTP)
*
* callback - Identifies the application function that will be called
* with AVCTP events.
*
* Returns:
* BT_STATUS_SUCCESS - The AVCTP application callback Function was
* successfully registered.
*
* BT_STATUS_IN_USE - The specified channel is already in use.
*
* BT_STATUS_INVALID_PARM - The chnl or Callback parameter does not
* contain a valid pointer (XA_ERROR_CHECK only), or psm is not a
* valid PSM value.
*/
BtStatus AVCTP_Register(AvctpChannel *chnl,
L2capPsmValue psm,
AvctpCallback callback);
/*---------------------------------------------------------------------------
* AVCTP_Deregister()
*
* De-registers the AVCTP callback. After making this call
* successfully, the callback specified in AVCTP_Register will
* receive no further events.
*
* Parameters:
*
* chnl - Channel structure that receives or initiates connections.
*
* Returns:
* BT_STATUS_SUCCESS - The AVCTP callback was successfully deregistered.
*
* BT_STATUS_IN_USE - The specified channel is still in use.
*
* BT_STATUS_NOT_FOUND - An AVCTP callback was not previously registered.
*
* BT_STATUS_INVALID_PARM - The chnl parameter does not contain a valid
* pointer. (XA_ERROR_CHECK only).
*/
BtStatus AVCTP_Deregister(AvctpChannel *chnl);
/*---------------------------------------------------------------------------
* AVCTP_Connect()
*
* Initiates a signal channel connection to a remote AVCTP device. This
* function is used to establish the lower layer connection (L2CAP), which
* allows sending signal messages. Only one connection can exist between
* two devices.
*
* If the connection attempt is successful, the AVCTP_EVENT_CONNECT event
* will be received. If the connection attempt is unsuccessful, the
* AVCTP_EVENT_DISCONNECT event will be received.
*
* Parameters:
*
* chnl - Channel structure that receives or initiates connections.
*
* remDev - A connected remote device.
*
* Returns:
*
* BT_STATUS_PENDING - The connection process has been successfully
* started. When the connection process is complete, the
* application callback will receive either the AVCTP_EVENT_CONNECT or
* AVCTP_EVENT_DISCONNECT event.
*
* BT_STATUS_IN_USE - The connection already exists.
*
* BT_STATUS_RESTRICTED - A connection of this type already exists with the
* remote device.
*
* BT_STATUS_NOT_FOUND - An AVCTP channel was not previously registered.
*
* BT_STATUS_INVALID_PARM - The chnl or addr parameter does not contain a
* valid pointer (XA_ERROR_CHECK only).
*
* Other - It is possible to receive other error codes, depending on the
* lower layer service in use (L2CAP or Management Entity).
*/
BtStatus AVCTP_Connect(AvctpChannel *chnl, BtRemoteDevice *RemDev);
/*---------------------------------------------------------------------------
* AVCTP_ConnectRsp()
*
* Responds to a connection request from the remote AVCTP device. This
* function is used to establish the lower layer connection (L2CAP),
* which allows sending signaling messages, such as discover,
* configuration, and stream management.
*
* Parameters:
*
* Chnl - A registered and open AVCTP channel.
*
* Accept - TRUE accepts the connect or FALSE rejects the connection.
*
* Returns:
*
* BT_STATUS_PENDING - The connection responses has been successfully
* sent. When the connection process is complete, the application
* callback will receive the AVCTP_EVENT_CONNECT event.
*
* BT_STATUS_BUSY - The connection is already connected.
*
* BT_STATUS_INVALID_PARM - The Chnl parameter does not contain a
* valid pointer. (XA_ERROR_CHECK only).
*
* BT_STATUS_NOT_FOUND - The specified device was not found in the device
* selector database. The device must be discovered, paired, or added
* manually using DS_AddDevice().
*
* Other - It is possible to receive other error codes, depending on the
* lower layer service in use (L2CAP or Management Entity).
*/
BtStatus AVCTP_ConnectRsp(AvctpChannel *Chnl, int Accept);
/*---------------------------------------------------------------------------
* AVCTP_Disconnect()
*
* Terminates a connection with a remote AVCTP device. The lower layer
* connection (L2CAP) is disconnected.
*
* Parameters:
*
* chnl - A registered and open AVCTP channel.
*
* Returns:
*
* BT_STATUS_PENDING - The disconnect process has been successfully
* started. When the disconnect process is complete, the
* application callback will receive the AVCTP_EVENT_DISCONNECT event.
*
* BT_STATUS_INVALID_PARM - The chnl parameter does not contain a valid
* pointer. (XA_ERROR_CHECK only).
*
* BT_STATUS_NO_CONNECTION - No connection exists on the specified
* channel.
*
* BT_STATUS_NOT_FOUND - The specified device was not found in the device
* selector database. The device must be discovered, paired, or added
* manually using DS_AddDevice().
*
* It is possible to receive other error codes, depending on the lower
* layer service in use (L2CAP or Management Entity).
*/
BtStatus AVCTP_Disconnect(AvctpChannel *chnl);
/*---------------------------------------------------------------------------
* AVCTP_SendCommand()
*
* Sends an AVCTP command on the specified channel. The channel must be
* connected and in the open state. The "cmdFrame" parameter must be
* set with valid AVCTP command parameters.
*
* Parameters:
*
* chnl - A registered and open AVCTP channel.
*
* cmdFrame - An AvctpCmdFrame structure initialized with valid
* AVCTP command parameters.
*
* Returns:
*
* BT_STATUS_PENDING - The send command operation has been started
* successfully. When the associated packet has been sent,
* the application callback will receive the AVCTP_EVENT_TX_DONE
* event.
*
* BT_STATUS_IN_USE - The command frame is alread in use on this channel.
*
* BT_STATUS_INVALID_PARM - The chnl parameter does not contain a valid
* pointer. (XA_ERROR_CHECK only).
*
* BT_STATUS_NOT_FOUND - The specified channel is not registered.
*/
BtStatus AVCTP_SendCommand(AvctpChannel *chnl, AvctpCmdFrame *cmdFrame);
/*---------------------------------------------------------------------------
* AVCTP_SendResponse()
*
* Sends an AVCTP response on the specified channel. The channel must be
* connected and in the open state. The "rspFrame" parameter must be
* set with valid AVCTP response parameters.
*
* Parameters:
*
* chnl - A registered and open AVCTP channel.
*
* rspFrame - An AvctpRspFrame structure initialized with valid
* AVCTP response parameters.
*
* Returns:
*
* BT_STATUS_PENDING - The send response operation has been started
* successfully. When the associated packet has been sent,
* the application callback will receive the AVCTP_EVENT_TX_DONE
* event.
*
* BT_STATUS_IN_USE - The response frame is alread in use on this channel.
*
* BT_STATUS_INVALID_PARM - The chnl parameter does not contain a valid
* pointer. (XA_ERROR_CHECK only).
*
* BT_STATUS_NOT_FOUND - The specified channel is not registered.
*/
BtStatus AVCTP_SendResponse(AvctpChannel *chnl, AvctpRspFrame *rspFrame);
/*---------------------------------------------------------------------------
* AVCTP_GetRemoteDevice()
*
* Returns a pointer to the current remote device.
*
* Parameters:
*
* chnl - An AVCTP channel.
*
* Returns:
*
* A pointer to a remote device.
*/
BtRemoteDevice * AVCTP_RemoteDevice(AvctpChannel *chnl);
#endif
#endif /* __AVCTP_H_ */

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,49 @@
/*
****************************************************************************************
*
* @file app_error.h
* @version v1.0
* @brief error code of app layer
* @attention
* Copyright (C) 2023 Freqchip. \n
* All rights reserved. \n
*
*
****************************************************************************************
*/
#ifndef __APP_ERROR_H_
#define __APP_ERROR_H_
typedef enum ble_api_error ble_api_err_t;
enum ble_api_error
{
/// no error
BLE_API_ERR_NO_ERR = 0x00,
/// the input parameter is incorrect
BLE_API_ERR_INVAILD_PARAM = 0x01,
/// the specified conidx has no device connection
BLE_API_ERR_DEVICE_NOT_CONNECTED = 0x02,
// ----------------------------------------------------
// ----------------- GATT API Error -------------------
// ----------------------------------------------------
/// invaild client_id or service_id
BLE_API_ERR_INVAILD_ID = 0x10,
/// GAP and GATT service is deleted
BLE_API_ERR_SVC_IS_DELETED = 0x11,
/// client handles group is empty
BLE_API_ERR_CLIENT_HDL_IS_EMPTY = 0x12,
// ----------------------------------------------------
// ----------------- GAP API Error --------------------
// ----------------------------------------------------
///has not been paired with the target device
BLE_API_ERR_NOT_PAIRED = 0x30,
///activity state error
BLE_ACT_STATE_IS_ERR = 0x31,
///Bond information has been lost
BLE_API_ERR_BOND_INFO_LOST = 0x32,
};
#endif

View File

@ -0,0 +1,255 @@
#ifndef _BT_ERROR_H
#define _BT_ERROR_H
#include <stdint.h>
#include "cmsis_compiler.h"
#include "btconfig.h"
#ifndef LISTS_DEFINED
#define LISTS_DEFINED
typedef struct _ListEntry
{
struct _ListEntry *Flink;
struct _ListEntry *Blink;
} ListEntry;
#define InitializeListEntry(Entry) (\
(Entry)->Flink = (Entry)->Blink = 0 )
#endif
typedef __PACKED_STRUCT bdaddr_t {
uint8_t A[6];
} BD_ADDR;
__PACKED_STRUCT class_of_device_t {
uint8_t A[3];
};
__PACKED_STRUCT link_key_t{
uint8_t A[16];
};
#define XA_DISABLED 0 /* Disable the feature */
#define XA_ENABLED 1 /* Enable the feature */
/*---------------------------------------------------------------------------
* BtStatus type
*
* This type is returned from most stack APIs to indicate the success
* or failure of the operation. In many cases, BT_STATUS_PENDING
* is returned, meaning that a future callback will indicate the
* result of the operation.
*/
typedef int16_t BtStatus;
#define BT_STATUS_SUCCESS 0
#define BT_STATUS_FAILED 1
#define BT_STATUS_PENDING 2
#define BT_STATUS_BUSY 11
#define BT_STATUS_NO_RESOURCES 12
#define BT_STATUS_NOT_FOUND 13
#define BT_STATUS_DEVICE_NOT_FOUND 14
#define BT_STATUS_CONNECTION_FAILED 15
#define BT_STATUS_TIMEOUT 16
#define BT_STATUS_NO_CONNECTION 17
#define BT_STATUS_INVALID_PARM 18
#define BT_STATUS_IN_PROGRESS 19
#define BT_STATUS_RESTRICTED 20
#define BT_STATUS_INVALID_TYPE 21
#define BT_STATUS_HCI_INIT_ERR 22
#define BT_STATUS_NOT_SUPPORTED 23
#define BT_STATUS_IN_USE 5
#define BT_STATUS_SDP_CONT_STATE 24
#define BT_STATUS_CANCELLED 25
/* The last defined status code */
#define BT_STATUS_LAST_CODE 25
/* Protocol extensions can safely add status codes by defining
* them as (BT_STATUS_OPEN + x).
*/
#define BT_STATUS_OPEN 30
/* End of BtStatus */
#define BD_ADDR_SIZE 6
#ifndef NULL
#define NULL 0
#endif
#ifndef SUCCESS
#define SUCCESS 0
#endif
#ifndef FAILURE
#define FAILURE 1
#endif
#ifndef TRUE
#define TRUE 1
#endif
#ifndef FALSE
#define FALSE 0
#endif
#define BIT0 0x00000001
#define BIT1 0x00000002
#define BIT2 0x00000004
#define BIT3 0x00000008
#define BIT4 0x00000010
#define BIT5 0x00000020
#define BIT6 0x00000040
#define BIT7 0x00000080
#define BIT8 0x00000100
#define BIT9 0x00000200
#define BIT10 0x00000400
#define BIT11 0x00000800
#define BIT12 0x00001000
#define BIT13 0x00002000
#define BIT14 0x00004000
#define BIT15 0x00008000
#define BIT16 0x00010000
#define BIT17 0x00020000
#define BIT18 0x00040000
#define BIT19 0x00080000
#define BIT20 0x00100000
#define BIT21 0x00200000
#define BIT22 0x00400000
#define BIT23 0x00800000
#define BIT24 0x01000000
#define BIT25 0x02000000
#define BIT26 0x04000000
#define BIT27 0x08000000
#define BIT28 0x10000000
#define BIT29 0x20000000
#define BIT30 0x40000000
#define BIT31 0x80000000
#if BT_SCO_HCI_DATA == XA_ENABLED
/*---------------------------------------------------------------------------
* CmgrAudioData structure
*
* Contains audio data.
*/
typedef struct _CmgrAudioData {
uint16_t len;
uint8_t *data;
#if BT_STACK_VERSION >= 300
uint8_t errFlags;
#endif
} CmgrAudioData;
/*---------------------------------------------------------------------------
* HfAudioData type
*
* This type is only available when BT_SCO_HCI_DATA is set to XA_ENABLED.
* It can be used to store audio data received from the remote device.
*/
typedef CmgrAudioData HfAudioData;
/* End of HfAudioData */
#endif /* BT_SCO_HCI_DATA == XA_ENABLED */
/*---------------------------------------------------------------------------
* BtPacket structure
*
* Represents a packet of data. These packets may be used by applications
* to provide data to the stack. Certain stack events may also provide
* data to the application enclosed in a BtPacket structure.
*/
typedef struct _BtPacket
{
ListEntry node; /* Used internally by the stack. */
uint8_t *data; /* Points to a buffer of user data. */
uint16_t dataLen; /* Indicates the length of "data" in bytes. */
uint16_t flags; /* Must be initialized to BTP_FLAG_NONE by
* applications running on top of L2CAP. Other
* higher layer protocols must never modify this
* value.
*/
#if L2CAP_PRIORITY == XA_ENABLED
BtPriority priority; /* May be used to override the L2CAP channel
* BtPriority. If set to 0, packet will use the
* default priority set for the L2CAP channel.
*/
#endif
/* Group: The following fields are for internal use only by the stack. */
void *ulpContext;
uint8_t *tail;
uint16_t tailLen;
#if XA_STATISTICS == XA_ENABLED
uint32_t rfc_timer;
uint32_t hci_timer;
uint32_t l2cap_timer;
#endif /* XA_STATISTICS == XA_ENABLED */
uint16_t llpContext;
uint16_t remoteCid;
#if L2CAP_NUM_ENHANCED_CHANNELS > 0
uint8_t segStart;
uint16_t segNum;
uint16_t segCount;
uint8_t fcs[2];
#endif /* L2CAP_NUM_ENHANCED_CHANNELS > 0 */
uint8_t hciPackets;
uint8_t headerLen;
uint8_t header[BT_PACKET_HEADER_LEN];
} BtPacket;
#if 1
typedef struct _EvmTimer EvmTimer;
/*---------------------------------------------------------------------------
* Callback used to notify a stack component that the timer expired.
*/
typedef void (*EvmTimerNotify)(EvmTimer*);
typedef void (*co_time_timer_cb)(void* p_env);
/// Timer structure
typedef struct co_time_timer
{
/// Pointer to next timer in timer list
struct co_time_timer * p_next;
/// Pointer to environment that will be used as callback parameter.
void* p_env;
/// Callback to execute in background context upon timer expiration
co_time_timer_cb cb;
/// Expiration time [0-31] part (in milliseconds)
uint32_t exp_time_ms_lsb;
/// Timer bit field (@see enum co_time_timer_bf)
uint32_t timer_bf;
} co_time_timer_t;
/*---------------------------------------------------------------------------
* EvmTimer structure
*
* Represents a stack timer. This structure is for use by
* internal stack components only.
*/
struct _EvmTimer
{
void *context; /* Context area for use by callers */
EvmTimerNotify func; /* Function to call when timer fires */
struct co_time_timer co_time;
};
#endif
#endif

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,357 @@
/*
* @file btdm_host.h
* @version v1.0
* @brief GAP API exposed to app layer
* @attention
* Copyright (c) 2022 Freqchip. \n
* All rights reserved. \n
*/
#ifndef _BTDM_HOST_H
#define _BTDM_HOST_H
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include <stdbool.h>
#include <stdint.h>
/* Exported types ------------------------------------------------------------*/
enum btdm_nvds_tag {
BTDM_NVDS_TAG_IRK, //!< local device irk
BTDM_NVDS_TAG_BOND_INFO, //!< BLE bonding information
BTDM_NVDS_TAG_MAX = BTDM_NVDS_TAG_BOND_INFO+16, //!< reserve 16 bonding information
BTDM_NVDS_TAG_CONTROLLER_INFO, //!< controller information
};
enum btdm_nvds_status {
BTDM_NVDS_STATUS_OK,
BTDM_NVDS_STATUS_FAILED,
};
struct ble_host_param {
/*
* this field is to indicate identity address is PUBLIC or RANDOM PRIVATE.
*/
uint8_t own_addr_type; // 0: public, 1:random static, other: unacceptable
/* local random static address, valied when own_addr_type is 1 */
struct {
uint8_t addr[6];
} own_addr;
};
/* Exported constants --------------------------------------------------------*/
/* Exported macro ------------------------------------------------------------*/
/* Private macros ------------------------------------------------------------*/
/* Exported functions --------------------------------------------------------*/
/*
* @fn ble_host_init
*
* @brief initialize ble host and HCI interface.
*
* param[in] param: BLE host parameters, @ref ble_host_param, default value is used when
* param is NULL
*/
void ble_host_init(struct ble_host_param *param);
/*
* @fn bt_host_init
*
* @brief initialize bt host, ble host should be ready before call this function.
*/
void bt_host_init(void);
/*
* @fn bt_a2dp_init
*
* @brief initialize a2dp profile, this function should be called following bt_stack_init.
*/
void bt_a2dp_init(void);
/*
* @fn bt_avrcp_init
*
* @brief initialize avrcp profile, this function should be called following bt_stack_init.
*/
void bt_avrcp_init(void);
/*
* @fn bt_hf_init
*
* @brief initialize HF profile, this function should be called following bt_stack_init.
*/
void bt_hf_init(void);
/*
* @fn bt_hfg_init
*
* @brief initialize HFG profile, this function should be called following bt_stack_init.
*/
void bt_hfg_init(void);
/*
* @fn bt_pan_init
*
* @brief initialize BNEP/PAN profile, this function should be called following bt_stack_init.
*/
void bt_pan_init(void);
/*
* @fn bt_hid_init
*
* @brief initialize HID profile, this function should be called following bt_stack_init.
*/
void bt_hid_init(void);
/*
* @fn bt_spp_init
*
* @brief initialize SPP profile, this function should be called following bt_stack_init.
*/
void bt_spp_init(void);
/*
* @fn bt_pbap_init
*
* @brief initialize PBAP profile, this function should be called following bt_stack_init.
*/
void bt_pbap_init(void);
/*
* @fn ble_host_ready
*
* @brief used to check whether ble host is ready or not.
*
* @return true: ble host is ready
*/
bool ble_host_ready(void);
/*
* @fn bt_host_ready
*
* @brief used to check whether bt host is ready or not.
*
* @return true: bt host is ready
*/
bool bt_host_ready(void);
/*
* @fn btdm_host_schedule
*
* @brief used to schedule btdm host internal event, this function should be called
* in system main loop.
*
* @example no RTOS:
* while(1) {
* btdm_host_schedule();
* // other process
* ...
* }
*
* RTOS:
* void stack_task(void)
* {
* while(1) {
* pending_new_event();
* btdm_host_schedule();
* }
* }
*
* void btdm_host_notify_schedule(void)
* {
* post_new_event();
* }
*/
void btdm_host_schedule(void);
/*
* @fn btdm_host_check_sleep
*
* @brief used to check whether system is allowed to enter sleep.
*
* @return true: btdm host can enter sleep right now
*/
bool btdm_host_check_sleep(void);
/*
* @fn btdm_host_schedule_ble
*
* @brief used to schedule ble host internal event, this function should be called
* in system main loop. This function is useful when only BLE is enabled.
*/
void btdm_host_schedule_ble(void);
/*
* @fn btdm_host_check_sleep_ble
*
* @brief used to check whether system is allowed to enter sleep. This function is useful
* when only BLE is enabled.
*
* @return true: ble host can enter sleep right now
*/
bool btdm_host_check_sleep_ble(void);
/*
* @fn btdm_timer_trigger
*
* @brief used to notice host timer is triggered.
*/
void btdm_timer_trigger(void);
/*
* @fn btdm_set_seed
*
* @brief initial seed for random generate function inside btdm stack.
*
* @param[in] seed: random seed.
*/
void btdm_set_seed(uint16_t seed);
/* Need to be implemented functions ------------------------------------------------*/
/*
* @fn btdm_malloc
*
* @brief allocate request size memory.
*
* @param[in] size: request size.
*
* @return allocated memory pointer
*/
void *btdm_malloc(uint32_t size);
/*
* @fn btdm_free
*
* @brief free allocated memory by btdm_malloc.
*
* @param[in] ptr: allocated memory pointer.
*/
void btdm_free(void *ptr);
/*
* @fn btdm_host_notify_schedule
*
* @brief used to notify btdm_host_schedule should be called to handle new btdm event,
* user should implement this function when RTOS is used, @ref btdm_host_schedule.
* Counting semaphore should be used because btdm_notify_schedule may be called more
* than one time before btdm_stack_schedule is called.
*/
void btdm_host_notify_schedule(void);
/*
* @fn btdm_host_lock
*
* @brief Called by the host to indicate the host and its APIs must not be entered by
* another task. This function should be implement when RTOS is used, and binary
* semaphore or mutex should be used.
*
* @example void btdm_stack_lock(void)
* {
* xSemaphoreTake();
* }
*/
void btdm_host_lock(void);
/*
* @fn btdm_host_unlock
*
* @brief Called by the host to allow access to the host again. This function should
* be implement when RTOS is used
*
* @example void btdm_stack_unlock(void)
* {
* xSemaphoreGive();
* }
*/
void btdm_host_unlock(void);
/*
* @fn btdm_timer_start
*
* @brief used to start or restart timer with target timeout time.
*
* @param[in] ms: timeout time(millisecond).
*/
void btdm_timer_start(uint32_t ms);
/*
* @fn btdm_timer_stop
*
* @brief used to stop timer.
*/
void btdm_timer_stop(void);
/*
* @fn btdm_get_system_time
*
* @brief used to get current time.
*
* @return current time(millisecond)
*/
uint32_t btdm_get_system_time(void);
/*
* @fn btdm_time_diff
*
* @brief Clocks time difference.
*
* @param[in] a_time value (in ms).
* @param[in] b_time value (in ms).
*
* @return result the time difference from a_time to b_time
* - result < 0 => b_time is in the past
* - result == 0 => a_time is equal to b_time
* - result > 0 => b_time is in the future
*/
int btdm_time_diff(uint32_t a_time, uint32_t b_time);
/*
* @fn btdm_nvds_put
*
* @brief Save generated data into NVDS.
*
* @param[in] tag: data type
* @param[in] length: data length
* @param[in] data: data pointer
*
* @return storage status, @ref btdm_nvds_status
*/
enum btdm_nvds_status btdm_nvds_put(uint8_t tag, uint16_t length, uint8_t *data);
/*
* @fn btdm_nvds_get
*
* @brief Get data from NVDS.
*
* @param[in] tag: data type
* @param[inout] length: buffer length for input, real data length for outpu
* @param[in] data: data pointer
*
* @return get data success or not, @ref btdm_nvds_status
*/
enum btdm_nvds_status btdm_nvds_get(uint8_t tag, uint16_t *length, uint8_t *buffer);
/*
* @fn btdm_nvds_del
*
* @brief delete data from NVDS with given tag.
*
* @param[in] tag: data type to be deleted
*
* @return delete success or not, @ref btdm_nvds_status
*/
enum btdm_nvds_status btdm_nvds_del(uint8_t tag);
#ifdef __cplusplus
}
#endif
#endif // _BTDM_HOST_H

View File

@ -0,0 +1,22 @@
#ifndef _BTDM_UTILS_H
#define _BTDM_UTILS_H
#include <stdint.h>
/* Little Endian to Host integer format conversion functions */
uint16_t LEtoHost16(const uint8_t *le_value);
uint32_t LEtoHost32(const uint8_t *le_value);
/* Big Endian to Host integer format conversion functions */
uint16_t BEtoHost16(const uint8_t* be_ptr);
uint32_t BEtoHost32(const uint8_t* be_ptr);
/* Store value into a buffer in Little Endian integer format */
void StoreLE16(uint8_t *buff, uint16_t le_value);
void StoreLE32(uint8_t *buff, uint32_t le_value);
/* Store value into a buffer in Big Endian integer format */
void StoreBE16(uint8_t *ptr, uint16_t be_value);
void StoreBE32(uint8_t *ptr, uint32_t be_value);
#endif // _BTDM_UTILS_H

View File

@ -0,0 +1,443 @@
/***************************************************************************
*
* File:
* $Id: config.h 588 2009-01-20 23:25:48Z gladed $
* $Product: iAnywhere Blue SDK v3.x $
* $Revision: 588 $
*
* Description:
* This file contains declarations for default protocol stack
* configuration.
*
* Created:
* November 19, 1996
*
* Copyright 1999-2005 Extended Systems, Inc.
* Portions copyright 2005-2008 iAnywhere Solutions, Inc.
* All rights reserved. All unpublished rights reserved.
*
* Unpublished Confidential Information of iAnywhere Solutions, Inc.
* Do Not Disclose.
*
* No part of this work may be used or reproduced in any form or by any
* means, or stored in a database or retrieval system, without prior written
* permission of iAnywhere Solutions, Inc.
*
* Use of this work is governed by a license granted by iAnywhere Solutions,
* Inc. This work contains confidential and proprietary information of
* iAnywhere Solutions, Inc. which is protected by copyright, trade secret,
* trademark and other intellectual property rights.
*
****************************************************************************/
#ifndef __CONFIG_H
#define __CONFIG_H
/*---------------------------------------------------------------------------
* General Configuration API layer
*
* The constants in this layer provide general configuration to
* communication protocol stacks compiled into the system. To change
* a constant, simply #define it in your overide.h include file.
*
* Configuration constants here and in other configuration API files
* are used to make the stack more appropriate for a particular
* environment. Constants can be modified to allow tradeoffs
* between code size, RAM usage, functionality, and throughput.
*
* Some constants are numeric, and others indicate whether a feature
* is enabled (defined as XA_ENABLED) or disabled (defined as
* XA_DISABLED).
*/
/****************************************************************************
*
* Constants
*
****************************************************************************/
#define XA_DISABLED 0 /* Disable the feature */
#define XA_ENABLED 1 /* Enable the feature */
/*---------------------------------------------------------------------------
* Include the override file. Settings in the override file will take
* precendence over the settings in this file and other configuration files.
*/
#include "overide.h"
/****************************************************************************
*
* Constants
*
****************************************************************************/
#ifndef XA_DEBUG
#if defined(XADEBUG) || defined(_DEBUG)
/*---------------------------------------------------------------------------
* XA_DEBUG constant
*
* When XA_DEBUG is enabled, debugging code is enabled throughout the
* stack, including OS_Report and OS_Assert calls and other code
* that verifies the proper behavior of the stack at run-time.
*
* When XA_DEBUG is disabled, debugging code is not compiled into the
* stack. Asserts and diagnostic output are removed. This results
* in a significant code size savings.
*
* You can specify the XA_DEBUG setting in the overide.h file. If it is
* not specified there, XA_DEBUG depends on the XADEBUG or _DEBUG
* constants defined at compile time. If XADEBUG or _DEBUG constants are
* defined, XA_DEBUG will be enabled. If the constants are not defined,
* XA_DEBUG will be disabled.
*/
#define XA_DEBUG XA_ENABLED
#else /* DEBUG symbols */
#define XA_DEBUG XA_DISABLED
#endif /* DEBUG symbols */
#endif /* XA_DEBUG not defined */
#ifndef XA_DEBUG_PRINT
/*---------------------------------------------------------------------------
* XA_DEBUG_PRINT constant
*
* When XA_DEBUG_PRINT is enabled, calls to OS_Report are
* enabled throughout the stack. These calls provide useful information
* about the internal state of the stack.
*
* When XA_DEBUG is disabled, OS_Report calls are not compiled into the
* stack. This results in a significant code size savings.
*
* By default, XA_DEBUG_PRINT inherits the state of the XA_DEBUG option.
* By setting it manually, you can control whether debug output messages
* appear independently of XA_DEBUG.
*/
#define XA_DEBUG_PRINT XA_DEBUG
#endif /* XA_DEBUG not defined */
#ifndef IRDA_STACK
/*---------------------------------------------------------------------------
* IRDA_STACK constant
*
* Controls whether IrDA-specific functionality is compiled into the
* system. This option is used in systems that can accommodate multiple
* transport mechanisms.
*
* By default, the IrDA stack is disabled.
*/
#define IRDA_STACK XA_DISABLED
#endif
#ifndef BT_STACK
/*---------------------------------------------------------------------------
* BT_STACK constant
*
* Controls whether Bluetooth-specific functionality is compiled into
* the system. This option is used in systems that can accommodate
* multiple transport mechanisms.
*/
#define BT_STACK XA_ENABLED
#endif
#ifndef XA_ERROR_CHECK
/*---------------------------------------------------------------------------
* XA_ERROR_CHECK constant
*
* Controls whether error checking code is compiled into the system.
*
* When XA_ERROR_CHECK is enabled, error checking code protects the
* stack API from illegal usage by verifying the entrance conditions
* for API call. This includes checking to make sure the API was called
* at the correct time, and checking each parameter for correctness
* before proceeding with any other processing.
*
* If an API returns a value marked XA_ERROR_CHECK only, the calling
* application has made a defective call which must be fixed.
*
* When XA_ERROR_CHECK is disabled, error checking code is not
* compiled into the system. This means that invalid API calls may
* cause strange errors to occur.
*
* Disabling error checking will result in significant code size savings,
* but it must only be disabled if you are confident that applications
* will not call stack APIs at inappropriate times or with invalid
* parameters.
*
* By default, error checking is enabled.
*/
#define XA_ERROR_CHECK XA_ENABLED
#endif
#ifndef XA_CONTEXT_PTR
/*---------------------------------------------------------------------------
* XA_CONTEXT_PTR constant
*
* Controls whether stack RAM is allocated dynamically or statically.
* All RAM used by stack components is kept in a stack context structure.
*
* When XA_CONTEXT_PTR is enabled, accesses to the context structure
* are performed using the "->" operand. This is required when
* the context structure is allocated dynamically (at run time).
*
* When XA_CONTEXT_PTR is disabled, accesses to the context structure
* are performed using the more efficient "." operand. This is allowed
* only if the context structure is allocated statically (at load time).
* This is more time- and ROM-efficient because references to stack
* variables are resolved at compile time rather than run time.
*
* Internally, all accesses to the stack context are protected through
* special macros. These macros are defined based on this configuration
* constant.
*
* By default, XA_CONTEXT_PTR is disabled.
*/
#define XA_CONTEXT_PTR XA_DISABLED
#endif /* XA_CONTEXT_PTR */
#ifndef XA_INTEGER_SIZE
/*---------------------------------------------------------------------------
* XA_INTEGER_SIZE constant
*
* Defines the preferred width of counter variables. In some systems,
* accesses to 2- or 4-byte variables is more time efficient than other
* sizes, even though they may take up more RAM. The stack attempts to
* honor this preference, except where a greater size is required.
*
* For instance, if XA_INTEGER_SIZE is defined as 2, 8-bit and 16-bit
* counters will both be defined as 16-bit variables.
*
* XA_INTEGER_SIZE may be 1, 2, or 4 and will affect the definition
* of I8, I16 types used internally by the stack. By default, 2-byte
* integers are preferred.
*/
#define XA_INTEGER_SIZE 2
#endif
#ifndef XA_USE_ENDIAN_MACROS
/*---------------------------------------------------------------------------
* XA_USE_ENDIAN_MACROS constant
*
* Controls how endian conversions are executed by the stack.
*
* When XA_USE_ENDIAN_MACROS is enabled, macros are used to perform
* big-endian and little-endian conversions. This increases overall
* ROM code size, but reduces RAM usage of the calling stack and
* reduces code execution time. Enabling XA_USE_ENDIAN_MACROS is similar
* to "inlining" all endian conversion routines.
*
* When XA_USE_ENDIAN_MACROS is disabled, function calls are substituted
* to convert big- and little-endian values. This increases execution
* time and calling stack RAM usage slightly, but decreases ROM code
* size.
*
* By default, endian macros are disabled (functions are used instead).
*/
#define XA_USE_ENDIAN_MACROS XA_DISABLED
#endif
#ifndef XA_MULTITASKING
/*---------------------------------------------------------------------------
* XA_MULTITASKING constant
*
* Controls whether the stack uses multitasking functions.
*
* When XA_MULTITASKING is enabled, the stack uses calls that protect
* the stack from reentrancy and minimize CPU usage. These calls include
* OS_StartTimer, OS_CancelTimer, OS_NotifyEvm, OS_LockStack, and
* OS_UnlockStack. This setting is appropriate when using a pre-emptive
* multitasking system.
*
* When XA_MULTITASKING is disabled, the functions listed above are not
* called by the stack. This is appropriate when using round-robin
* task scheduler that does not allow task blocking.
*
* By default, multitasking features are disabled.
*/
#define XA_MULTITASKING XA_ENABLED
#endif
#ifndef MS_TO_TICKS
/*---------------------------------------------------------------------------
* MS_TO_TICKS()
*
* Defines the conversion between system ticks and milliseconds. On some
* platforms, OS_GetSystemTime returns values in ticks instead of
* milliseconds. In this case, MS_TO_TICKS must be defined to
* convert a duration expressed in milliseconds to ticks.
*
* For example, a system with 4.4 millisecond ticks should define this
* macro in overide.h as follows:
*
* #define MS_TO_TICKS(ms) ((ms)*10/44)
*
* By default, no conversion is performed. This is appropriate when
* OS_GetSystemTime is able to return values in milliseconds.
*/
#define MS_TO_TICKS(ms) (ms)
#endif
#ifndef ContainingRecord
/*---------------------------------------------------------------------------
* ContainingRecord()
* Calculate the address of the base of the structure given its type
* and the address of a field within the structure.
*
* While this definition is within ANSI standards, there will probably
* be some compiler that has a problem with it. When in XA_DEBUG mode,
* a function called VerifyMacros exists that checks the behavior of
* this macro. This function will assert if this implementation of
* ContainingRecord does not work with your compiler.
*
* You may redefine the behavior of this macro by declaring a different
* version of it in your overide.h file.
*
* Parameters:
* fieldAddr - address of 'memberName'
*
* structType - structure type that contains 'memberName'
*
* memberName - name of structure member located at 'fieldAddr'
*
* Returns:
* The address of 'structType' that contains 'memberName' at 'fieldAddr'
*/
/*@notfunction@*/
#define ContainingRecord(fieldAddr, structType, memberName) ((structType *)( \
(U8 *)(fieldAddr) - (U8 *)(&((structType *)0)->memberName)))
#endif
#ifndef XA_EVENTMGR
/*---------------------------------------------------------------------------
* XA_EVENTMGR constant
*
* Controls whether the Event Manager functionality is compiled into the
* system. This option is used to enable the Event Manager when the stack
* transport does not automatically include it. Note that Event Manager
* support is always included in IrDA and Bluetooth stack builds.
*
* By default, the Event Manager is disabled.
*/
#define XA_EVENTMGR XA_DISABLED
#endif
#ifndef XA_SNIFFER
/*---------------------------------------------------------------------------
* XA_SNIFFER constant
*
* Controls whether the protocol sniffer hooks in various protocol layers
* are compiled into the system. The sniffer uses an endpoint registration
* function to manage a connection table which is used as a guide when
* decoding data packets. When enabled, the function SnifferRegisterEndpoint
* as described in debug.h must be implemented. When disabled, the sniffer
* functionality can still be accessed, but protocol specific decoding will
* stop at the L2CAP layer.
*
* By default, this option is disabled.
*/
#define XA_SNIFFER XA_DISABLED
#endif
#ifndef XA_DECODER
#if (XA_SNIFFER == XA_ENABLED) || (XA_DEBUG_PRINT == XA_ENABLED)
/*---------------------------------------------------------------------------
* XA_DECODER constant
*
* Determines whether the XA Decoder subsystem is included. This system
* allows internal stack components, profiles, and applications to
* register integer types for decoding at runtime, resulting in more
* readable debug log entries and displays. These calls are documented
* in utils.h.
*
* By default, XA_DECODER is enabled if either XA_DEBUG_PRINT or
* XA_SNIFFER are enabled.
*/
#define XA_DECODER XA_ENABLED
#else
#define XA_DECODER XA_DISABLED
#endif /* (XA_SNIFFER == XA_ENABLED) || (XA_DEBUG_PRINT == XA_ENABLED) */
#endif /* XA_DECODER */
#ifndef XA_LOAD_LIST
/*---------------------------------------------------------------------------
* XA_LOAD_LIST constant
*
* Specifies any optional protocol or profile components in this build,
* which require initialization. The core IrDA and Bluetooth protocols are
* not used in this constant. The components will be initialized in the
* order specified by this constant. If a component requires inclusion on
* this load list, it will be stated along with the initialization function
* prototype, in the main header file for the component and in the Implementer's
* Guide under the section for the profile or component being implemented.
*
* An example usage of this constant to initialize an OBEX based application is:
* #define XA_LOAD_LIST XA_MODULE(OBEX)
*
* Which will insert the following code in the event manager:
* extern BOOL OBEX_Init(void);
* if ((OBEX_Init && TRUE) != TRUE) { return FALSE; }
*
* An example of a implementation using GOEP and OBEX is:
* #define XA_LOAD_LIST XA_MODULE(OBEX) XA_MODULE(GOEP)
*
* By default, no optional protocol or profile modules are initialized.
*/
#define XA_LOAD_LIST
#endif
#ifndef XA_STATISTICS
/*---------------------------------------------------------------------------
* XA_STATISTICS constant
*
* Controls internal statistics-gathering macros. When enabled,
* certain stack components keep track of resource usage and timing.
* To extract this information, a module in your system must include
* /inc/sys/btstats.h and call BTSTAT_Report, which will send a
* set of statistics to debug output.
*
* For more information about the meaning of each statistic, see
* the Blue SDK Implementer's Guide.
*
* By default, statistics-gathering is disabled to save code size.
*
* Requires:
* XA_DEBUG enabled.
*/
#define XA_STATISTICS XA_DISABLED
#endif
#if XA_DEBUG == XA_DISABLED
#undef XA_STATISTICS
#define XA_STATISTICS XA_DISABLED
#endif
/*---------------------------------------------------------------------------
* Some pragmas to disable useless level-4 warnings. These are
* specific to MSVC.
*/
#ifdef WIN32
/* Conditional comparisons are not a problem */
#pragma warning(disable:4127)
/* Intentionally converting int to U8/U16 is done frequently, especially
* with += operators. */
#pragma warning(disable:4244)
/* If we cast a U16 constant to a U8, let's assume that was intentional */
#pragma warning(disable:4310)
#endif /* WIN32 */
#endif /* __CONFIG_H */

View File

@ -0,0 +1,356 @@
#ifndef _GAF_API_H
#define _GAF_API_H
#include <stdint.h>
#include "gap_api.h"
/// Length of Codec ID value
#define GAF_CODEC_ID_LEN (5)
#define GAF_KEY_LEN (16)
/// Event ID for callback
enum gaf_cb_event_id
{
GAF_BAP_CONFIGURED,
GAF_BAP_BC_SRC_GROUP_ADDED,
GAF_BAP_BC_SRC_GROUP_SET,
GAF_BAP_BC_SRC_SUBGROUP_SET,
GAF_BAP_BC_SRC_STREAM_SET,
GAF_BAP_BC_SRC_PA_ENABLED,
GAF_BAP_BC_SRC_ENABLED,
GAF_BAP_BC_SRC_STREAM_STARTED,
GAF_BAP_BC_SCAN_STARTED,
GAF_BAP_BC_SCAN_STOPPED,
GAF_BAP_BC_SCAN_PA_SYNC_STARTED,
GAF_BAP_BC_SCAN_PARAM_SET,
GAF_BAP_BC_SCAN_TIMEOUT,
GAF_BAP_BC_SCAN_REPORT,
GAF_BAP_BC_SCAN_PA_ESTABLISHED,
GAF_BAP_BC_SCAN_PA_TERMINATED,
GAF_BAP_BC_SCAN_PA_REPORT,
GAF_BAP_BC_SCAN_BIG_INFO_REPORT,
GAF_BAP_BC_SCAN_GROUP_REPORT,
GAF_BAP_BC_SCAN_SUBGROUP_REPORT,
GAF_BAP_BC_SCAN_STREAM_REPORT,
GAF_BAP_BC_SINK_ENABLED,
GAF_BAP_BC_SINK_STREAM_STARTED,
GAF_BAP_BC_SINK_ISO_DATA,
GAF_UNHANDLED_MSG,
};
/// Response Code values for ASE Control Point characteristic
enum bap_uc_cp_rsp_code
{
/// Success
BAP_UC_CP_RSP_CODE_SUCCESS = 0,
/// Unsupported Opcode
BAP_UC_CP_RSP_CODE_UNSUPPORTED_OPCODE,
/// Truncated Operation
BAP_UC_CP_RSP_CODE_TRUNACTED_OPERATION,
/// Invalid ASE ID
BAP_UC_CP_RSP_CODE_INVALID_ASE_ID,
/// Invalid ASE State Machine Transition
BAP_UC_CP_RSP_CODE_INVALID_TRANSITION,
/// Unsupported Audio Capabilities
BAP_UC_CP_RSP_CODE_UNSUPPORTED_AUDIO_CAPA,
/// Unsupported Configuration Parameter value
BAP_UC_CP_RSP_CODE_UNSUPPORTED_CFG_PARAM,
/// Rejected Configuration Parameter value
BAP_UC_CP_RSP_CODE_REJECTED_CFG_PARAM,
/// Invalid Configuration Parameter value
BAP_UC_CP_RSP_CODE_INVALID_CFG_PARAM,
/// Unsupported Metadata
BAP_UC_CP_RSP_CODE_UNSUPPORTED_METADATA,
/// Rejected Metadata
BAP_UC_CP_RSP_CODE_REJECTED_METADATA,
/// Invalid Metadata
BAP_UC_CP_RSP_CODE_INVALID_METADATA,
/// Insufficient Resources
BAP_UC_CP_RSP_CODE_INSUFFICIENT_RESOURCES,
/// Unspecified Error
BAP_UC_CP_RSP_CODE_UNSPECIFIED_ERROR,
BAP_UC_CP_RSP_CODE_MAX,
};
/// Reason values for ASE Control Point characteristic
enum bap_uc_cp_reason
{
BAP_UC_CP_REASON_MIN = 1,
/// Direction
BAP_UC_CP_REASON_DIRECTION = BAP_UC_CP_REASON_MIN,
/// Codec ID
BAP_UC_CP_REASON_CODEC_ID,
/// Codec Specific Configuration Length
BAP_UC_CP_REASON_CODEC_CFG_LEN,
/// Codec Specific Configuration
BAP_UC_CP_REASON_CODEC_CFG,
/// SDU Interval
BAP_UC_CP_REASON_SDU_INTERVAL,
/// Framing
BAP_UC_CP_REASON_FRAMING,
/// PHY
BAP_UC_CP_REASON_PHY,
/// Maximum SDU Size
BAP_UC_CP_REASON_MAX_SDU_SIZE,
/// Retransmission Number
BAP_UC_CP_REASON_RETX_NB,
/// Transport Latency
BAP_UC_CP_REASON_TRANS_LATENCY,
/// Presentation Delay
BAP_UC_CP_REASON_PRES_DELAY,
/// Metadata length
BAP_UC_CP_REASON_METADATA_LEN,
BAP_UC_CP_REASON_MAX,
};
/// Codec Identifier
typedef struct gaf_codec_id
{
/// Codec ID value
uint8_t codec_id[GAF_CODEC_ID_LEN];
} gaf_codec_id_t;
/// Broadcast code used for stream encryption
typedef struct gaf_bcast_code_t
{
/// Broadcast Code value
uint8_t bcast_code[GAF_KEY_LEN];
} gaf_bcast_code_t;
/// QoS Requirement structure
typedef struct bap_qos_req
{
/// Preferred SDU interval minimum in microseconds
/// From 255us (0xFF) to 16777215us (0xFFFFFF)
uint32_t sdu_intv_min_us;
/// Preferred SDU interval maximum in microseconds
/// From 255us (0xFF) to 16777215us (0xFFFFFF)
uint32_t sdu_intv_max_us;
/// Presentation delay minimum microseconds
uint32_t pres_delay_min_us;
/// Presentation delay maximum in microseconds
uint32_t pres_delay_max_us;
/// Preferred Transport latency maximum in milliseconds
/// From 5ms (0x5) to 4000ms (0xFA0)
uint16_t trans_latency_max_ms;
/// Preferred maximum SDU size
/// From 0 to 4095 bytes (0xFFF)
uint16_t max_sdu_size;
/// Preferred PDU framing arrangement
uint8_t framing;
/// Preferred PHY bit field
uint8_t phy_bf;
/// Preferred maximum number of retransmissions for each CIS Data PDU
/// From 0 to 15
uint8_t retx_nb;
} bap_qos_req_t;
/// Broadcast Group Parameters structure
typedef struct bap_bc_grp_param
{
/// SDU interval in microseconds
uint32_t sdu_intv_us;
/// Maximum size of an SDU
uint16_t max_sdu;
/// Maximum time (in milliseconds) between the first transmission of an SDU to the end of the last transmission
/// of the same SDU
uint16_t max_tlatency;
/// Sequential or Interleaved scheduling
uint8_t packing;
/// Unframed or framed mode
uint8_t framing;
/// Bitfield indicating PHYs that can be used by the controller for transmission of SDUs
uint8_t phy_bf;
/// Number of times every PDU should be transmitted
uint8_t rtn;
}bap_bc_grp_param_t;
/// Advertising Parameters structure
typedef struct bap_bc_adv_param
{
/// Minimum advertising interval in multiple of 0.625ms. Must be higher than 20ms.
uint32_t adv_intv_min_slot;
/// Maximum advertising interval in multiple of 0.625ms. Must be higher than 20ms.
uint32_t adv_intv_max_slot;
/// Channel Map
uint8_t chnl_map;
/// PHY for primary advertising. Only LE 1M and LE Codec PHYs are allowed
uint8_t phy_prim;
/// PHY for secondary advertising
uint8_t phy_second;
/// Advertising SID
uint8_t adv_sid;
}bap_bc_adv_param_t;
/// Periodic Advertising Parameters structure
typedef struct bap_bc_per_adv_param
{
/// Minimum periodic advertising interval in multiple of 1.25ms. Must be higher than 7.5ms
uint32_t adv_intv_min_frame;
/// Maximum periodic advertising interval in multiple of 1.25ms. Must be higher than 7.5ms
uint32_t adv_intv_max_frame;
} bap_bc_per_adv_param_t;
/// BIG Info Report
typedef struct gaf_big_info
{
/// Value of the SDU interval in microseconds (Range 0x0000FF-0x0FFFFF)
uint32_t sdu_interval;
/// Value of the ISO Interval (1.25 ms unit)
uint16_t iso_interval;
/// Value of the maximum PDU size (Range 0x0000-0x00FB)
uint16_t max_pdu;
/// VValue of the maximum SDU size (Range 0x0000-0x0FFF)
uint16_t max_sdu;
/// Number of BIS present in the group (Range 0x01-0x1F)
uint8_t num_bis;
/// Number of sub-events (Range 0x01-0x1F)
uint8_t nse;
/// Burst number (Range 0x01-0x07)
uint8_t bn;
/// Pre-transmit offset (Range 0x00-0x0F)
uint8_t pto;
/// Initial retransmission count (Range 0x01-0x0F)
uint8_t irc;
/// PHY used for transmission (0x01: 1M, 0x02: 2M, 0x03: Coded, All other values: RFU)
uint8_t phy;
/// Framing mode (0x00: Unframed, 0x01: Framed, All other values: RFU)
uint8_t framing;
/// True if broadcast isochronous group is encrypted, False otherwise
bool encrypted;
} gaf_big_info_t;
typedef struct gaf_iso_data {
uint16_t sdu_seq;
uint16_t length;
uint8_t *buffer;
bool ts_exist;
uint32_t ts;
} gaf_iso_data_t;
typedef union _gaf_callback_param {
uint16_t status;
struct {
struct gap_ble_addr addr;
uint8_t adv_sid;
uint8_t length;
uint8_t *data;
} scan_report;
struct {
uint8_t pa_lid;
struct gap_ble_addr addr;
uint8_t adv_sid;
} scan_pa_establised;
struct {
uint8_t pa_lid;
uint8_t reason;
} scan_pa_terminated;
struct {
uint8_t pa_lid;
uint8_t length;
uint8_t *data;
} scan_pa_report;
struct {
uint8_t pa_lid;
struct gaf_big_info *big_info;
} scan_big_info_report;
struct {
uint8_t pa_lid;
uint8_t nb_subgroup;
uint8_t nb_stream;
uint32_t pres_delay_us;
} scan_group_report;
struct {
uint8_t pa_lid;
uint8_t subgroup_lid;
gaf_codec_id_t *codec_id;
uint32_t stream_pos_bf;
uint8_t cfg_len;
uint8_t metadata_len;
uint8_t *cfg;
uint8_t *metadata;
} scan_subgroup_report;
struct {
uint8_t pa_lid;
uint32_t stream_pos;
uint8_t cfg_len;
uint8_t *cfg;
} scan_stream_report;
struct {
uint8_t stream_lid;
bool ts_exist;
uint32_t ts;
uint16_t sdu_seq;
uint16_t length;
uint8_t *buffer;
} sink_iso_data;
struct {
uint16_t msg_type;
uint16_t cmd_code;
uint16_t status;
} unhandled_msg;
} gaf_callback_param_t;
typedef void (*gaf_callback_t)(uint8_t event, gaf_callback_param_t *param);
void gaf_cfg(gaf_callback_t cb);
void gaf_bap_capa_record_add(uint8_t pac_id, uint8_t record_id, gaf_codec_id_t *codec_id, uint16_t cap_len, uint8_t *cap);
void gaf_bap_capa_record_remove(uint8_t record_id);
void gaf_bap_uc_srv_codec_configure(uint8_t con_lid, uint8_t ase_lid, uint8_t ase_instance_idx, uint8_t direction, uint8_t dp_id,
gaf_codec_id_t *codec_id, bap_qos_req_t *qos_req, uint32_t ctl_delay_us,
uint16_t cfg_len, uint8_t *cfg);
void gaf_bap_uc_srv_codec_configure_cfm(uint16_t status, uint8_t rsp_code, uint8_t reason, uint8_t ase_lid, uint8_t dp_id,
gaf_codec_id_t *codec_id, bap_qos_req_t *qos_req, uint32_t ctl_delay_us,
uint16_t cfg_len, uint8_t *cfg);
void gaf_bap_bc_src_group_add(uint8_t nb_stream, uint8_t nb_subgroups,
bap_bc_grp_param_t *grp_param,
bap_bc_adv_param_t *adv_param,
bap_bc_per_adv_param_t *per_adv_param);
void gaf_bap_bc_src_group_set(uint8_t grp_lid, uint32_t pres_delay_us, gaf_codec_id_t *codec_id,
uint8_t cfg_len, uint8_t metadata_len, uint8_t *val);
void gaf_bap_bc_src_subgroup_set(uint8_t grp_lid, uint8_t sgrp_lid,
uint8_t metadata_len, uint8_t *metadata);
void gaf_bap_bc_src_stream_set(uint8_t grp_lid, uint8_t sgrp_lid, uint8_t stream_lid, uint32_t ctl_delay_us, uint8_t dp_id,
uint8_t cfg_len, uint8_t *cfg);
void gaf_bap_bc_src_pa_enable(uint8_t grp_lid, uint8_t adv_data_len, uint8_t per_adv_data_len, uint8_t *data);
void gaf_bap_bc_src_enable(uint8_t grp_lid, uint8_t encrypted, gaf_bcast_code_t *bcast_code);
void gaf_bap_bc_src_stream_start(uint8_t grp_lid, uint32_t stream_lid_bf);
void gaf_bap_bc_src_send_data(uint8_t grp_lid, uint8_t stream_lid, gaf_iso_data_t *data);
void gaf_bap_bc_scan_set_param(uint16_t intv_1m_slot, uint16_t intv_coded_slot,
uint16_t wd_1m_slot, uint16_t wd_coded_slot);
void gaf_bap_bc_scan_start(uint16_t timeout_s);
void gaf_bap_bc_scan_stop(void);
void gaf_bap_bc_scan_pa_sync(struct gap_ble_addr *addr, uint8_t adv_sid, uint16_t skip, uint8_t report_filter_bf, uint16_t sync_to, uint16_t timeout_s);
void gaf_bap_bc_sink_enable(uint8_t pa_lid, uint8_t mse, uint32_t stream_pos_bf,
uint16_t timeout_s,
uint8_t encrypted,
gaf_bcast_code_t *bcast_code);
void gaf_bap_bc_sink_stream_start(uint8_t grp_lid, uint8_t stream_pos, uint32_t ctl_delay_us,
gaf_codec_id_t *codec_id,
uint8_t dp_id, uint8_t cfg_len,
uint8_t *cfg);
#endif // _GAF_API_H

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,156 @@
#ifndef _GAP_DEFINES_H
#define _GAP_DEFINES_H
/// Own BD address source of the device
enum gapm_own_addr
{
/// Public or Private Static Address according to device address configuration
GAPM_STATIC_ADDR,
/// Generated resolvable private random address
GAPM_GEN_RSLV_ADDR,
/// Generated non-resolvable private random address
GAPM_GEN_NON_RSLV_ADDR,
};
/// PHY Type
enum gapm_phy_type
{
/// LE 1M
GAPM_PHY_TYPE_LE_1M = 1,
/// LE 2M
GAPM_PHY_TYPE_LE_2M,
/// LE Coded
GAPM_PHY_TYPE_LE_CODED,
};
/// PHY Type
enum gapm_phy_mask
{
/// LE 1M
GAPM_PHY_MASK_LE_1M = (1 << 0),
/// LE 2M
GAPM_PHY_MASK_LE_2M = (1 << 1),
/// LE Coded
GAPM_PHY_MASK_LE_CODED = (1 << 2),
/// ALL
GAPM_PHY_MASK_ALL = (GAPM_PHY_MASK_LE_1M | GAPM_PHY_MASK_LE_2M | GAPM_PHY_MASK_LE_CODED),
};
/// Type of advertising that can be created
enum gapm_adv_type
{
/// Legacy advertising
GAPM_ADV_TYPE_LEGACY = 0,
/// Extended advertising
GAPM_ADV_TYPE_EXTENDED,
/// Periodic advertising
GAPM_ADV_TYPE_PERIODIC,
};
/// Advertising discovery mode
enum gapm_adv_disc_mode
{
/// Mode in non-discoverable
GAPM_ADV_MODE_NON_DISC = 0,
/// Mode in general discoverable
GAPM_ADV_MODE_GEN_DISC,
/// Mode in limited discoverable
GAPM_ADV_MODE_LIM_DISC,
/// Broadcast mode without presence of AD_TYPE_FLAG in advertising data
GAPM_ADV_MODE_BEACON,
GAPM_ADV_MODE_MAX,
};
/// Advertising properties bit field bit positions
enum gapm_adv_prop_bf
{
/// Indicate that advertising is connectable, reception of CONNECT_REQ or AUX_CONNECT_REQ
/// PDUs is accepted. Not applicable for periodic advertising.
GAPM_ADV_PROP_CONNECTABLE_POS = 0,
GAPM_ADV_PROP_CONNECTABLE_BIT = 0x0001,
/// Indicate that advertising is scannable, reception of SCAN_REQ or AUX_SCAN_REQ PDUs is
/// accepted
GAPM_ADV_PROP_SCANNABLE_POS = 1,
GAPM_ADV_PROP_SCANNABLE_BIT = 0x0002,
/// Indicate that advertising targets a specific device. Only apply in following cases:
/// - Legacy advertising: if connectable
/// - Extended advertising: connectable or (non connectable and non discoverable)
GAPM_ADV_PROP_DIRECTED_POS = 2,
GAPM_ADV_PROP_DIRECTED_BIT = 0x0004,
/// Indicate that High Duty Cycle has to be used for advertising on primary channel
/// Apply only if created advertising is not an extended advertising
GAPM_ADV_PROP_HDC_POS = 3,
GAPM_ADV_PROP_HDC_BIT = 0x0008,
/// Bit 4 is reserved
GAPM_ADV_PROP_RESERVED_4_POS = 4,
GAPM_ADV_PROP_RESERVED_4_BIT = 0x0010,
/// Enable anonymous mode. Device address won't appear in send PDUs
/// Valid only if created advertising is an extended advertising
GAPM_ADV_PROP_ANONYMOUS_POS = 5,
GAPM_ADV_PROP_ANONYMOUS_BIT = 0x0020,
/// Include TX Power in the extended header of the advertising PDU.
/// Valid only if created advertising is not a legacy advertising
GAPM_ADV_PROP_TX_PWR_POS = 6,
GAPM_ADV_PROP_TX_PWR_BIT = 0x0040,
/// Include TX Power in the periodic advertising PDU.
/// Valid only if created advertising is a periodic advertising
GAPM_ADV_PROP_PER_TX_PWR_POS = 7,
GAPM_ADV_PROP_PER_TX_PWR_BIT = 0x0080,
/// Indicate if application must be informed about received scan requests PDUs
GAPM_ADV_PROP_SCAN_REQ_NTF_EN_POS = 8,
GAPM_ADV_PROP_SCAN_REQ_NTF_EN_BIT = 0x0100,
};
/// Scanning Types
enum gapm_scan_type
{
/// General discovery
GAPM_SCAN_TYPE_GEN_DISC = 0,
/// Limited discovery
GAPM_SCAN_TYPE_LIM_DISC,
/// Observer
GAPM_SCAN_TYPE_OBSERVER,
/// Selective observer
GAPM_SCAN_TYPE_SEL_OBSERVER,
/// Connectable discovery
GAPM_SCAN_TYPE_CONN_DISC,
/// Selective connectable discovery
GAPM_SCAN_TYPE_SEL_CONN_DISC,
};
/// IO Capability Values
enum gap_io_cap
{
/// Display Only
GAP_IO_CAP_DISPLAY_ONLY = 0x00,
/// Display Yes No
GAP_IO_CAP_DISPLAY_YES_NO,
/// Keyboard Only
GAP_IO_CAP_KB_ONLY,
/// No Input No Output
GAP_IO_CAP_NO_INPUT_NO_OUTPUT,
/// Keyboard Display
GAP_IO_CAP_KB_DISPLAY,
GAP_IO_CAP_LAST
};
/// OOB Data Present Flag Values
enum gap_oob
{
/// OOB Data not present
GAP_OOB_AUTH_DATA_NOT_PRESENT = 0x00,
/// OOB data present
GAP_OOB_AUTH_DATA_PRESENT,
GAP_OOB_AUTH_DATA_LAST
};
#endif // _GAP_DEFINES_H

View File

@ -0,0 +1,532 @@
#ifndef _GATT_API_H
#define _GATT_API_H
/* Includes ------------------------------------------------------------------*/
#include <stdint.h>
#include "gatt_defines.h"
#include "gatt_sig_uuid.h"
#include "ble_api_error.h"
/* Exported types ------------------------------------------------------------*/
enum gatt_msg_evt {
GATTS_MSG_READ_REQ, //!< GATT service received read request
GATTS_MSG_WRITE_REQ, //!< GATT service received write request
GATTS_MSG_ATT_INFO_REQ, //!< GATT service received get att information request
GATTC_MSG_NTF_REQ, //!< GATT client notification received
GATTC_MSG_IND_REQ, //!< GATT client indication received
GATTC_MSG_READ_IND, //!< GATT client read response received
GATTC_MSG_CMP_EVT, //!< GATT client message complete event
GATTC_MSG_LINK_CREATE, //!< A Link is established
GATTC_MSG_LINK_LOST, //!< A Link is lost
GATTC_MSG_SVC_REPORT, //!< GATT client received report of service discovery
GATTC_MSG_CHAR_REPORT, //!< GATT client received report of characteristic discovery
GATTC_MSG_CHAR_DESC_REPORT, //!< GATT client received report of characteristic describtion discovery
};
enum gatt_event_type {
ENABLE_TYPE_NTF, //!< notification type
ENABLE_TYPE_IND, //!< indication type
};
#define UUID_SIZE_2 2 //!< 16-bits UUID, usually SIG assigned UUID.
#define UUID_SIZE_4 4 //!< 32-bits UUID, usually assigned by users.
#define UUID_SIZE_16 16 //!< 128-bits UUID, usually assigned by users.
/** @defgroup GATT_PROP_BITMAPS_DEFINES GATT Attribute Access Permissions Bit Fields
* @{
*/
#define GATT_PROP_BROADCAST (1<<0) //!< Attribute is able to broadcast
#define GATT_PROP_READ (1<<1) //!< Attribute is Readable
#define GATT_PROP_WRITE_CMD (1<<2) //!< Attribute supports write with no response
#define GATT_PROP_WRITE_REQ (1<<3) //!< Attribute supports write request
#define GATT_PROP_NOTI (1<<4) //!< Attribute is able to send notification
#define GATT_PROP_INDI (1<<5) //!< Attribute is able to send indication
#define GATT_PROP_SIG_WRTIE (1<<6) //!< Attribute supports authenticated signed write
#define GATT_PROP_EXTEND_PROP (1<<7) //!< Attribute supports extended properities
#define GATT_PROP_READ_UNAUTH (1<<8) //!< Attribute read requires Unauthentication(Just work pairring method)
#define GATT_PROP_READ_AUTHEN (2<<8) //!< Attribute read requires Authentication(Legacy mode. Pass key or OOB pairring method)
#define GATT_PROP_READ_SECURE_CONN (3<<8) //!< Attribute read requires Secure Connection(Secure connect mode. Pass key\OOB\Numbric Comparision pairing method)
#define GATT_PROP_WRITE_UNAUTH (1<<10) //!< Attribute write requires Unauthentication
#define GATT_PROP_WRITE_AUTHEN (2<<10) //!< Attribute write requires Authentication
#define GATT_PROP_WRITE_SECURE_CONN (3<<10) //!< Attribute write requires Secure Connection
#define GATT_PROP_NI_UNAUTH (1<<12) //!< Attribute notification or indication requires Unauthentication
#define GATT_PROP_NI_AUTHEN (2<<12) //!< Attribute notification or indication requires Authentication
#define GATT_PROP_NI_SECURE_CONN (3<<12) //!< Attribute notification or indication requires Secure Connection
/** @} End GATT_PERMIT_BITMAPS_DEFINES */
/** @defgroup GATT_OPERATION_NAME_DEFINES GATT operation name define, used with GATTC_MSG_CMP_EVT
* @{
*/
#define GATT_OP_NOTIFY 0x01 //!< GATT notification operation
#define GATT_OP_INDICA 0x02 //!< GATT indication operation
#define GATT_OP_PEER_SVC_REGISTERED 0x03 //!< Used with GATTC_CMP_EVT, GATT peer device service registered
#define GATT_OP_WRITE_REQ 0x05 //!< GATT wirte request operation
#define GATT_OP_WRITE_CMD 0x06 //!< GATT wirte command operation, write without response
#define GATT_OP_READ 0x07 //!< GATT read operation
#define GATT_OP_PEER_SVC_DISC_END 0x08 //!< Used with GATTC_CMP_EVT, GATT peer device service discovery is ended
#define GATT_OP_PEER_CHAR_DISC_END 0X09 //!< Used with GATTC_CMP_EVT, GATT peer device characteristic discovery is ended
#define GATT_OP_PEER_DESC_DISC_END 0X0A //!< Used with GATTC_CMP_EVT, GATT peer device characteristic describtion discovery is ended
/** @} End GATT_OPERATION_NAME_DEFINES */
struct gatt_msg {
enum gatt_msg_evt msg_evt; //!< The event that message come with
uint8_t conn_idx; //!< Connection index
uint8_t svc_id; //!< service id of this message
uint16_t att_idx; //!< Attribute index of in the service table or client uuid table
uint16_t handle; //!< Attribute handle number in peer service
union {
struct {
uint8_t operation; //!< GATT request type, see @GATT_OPERATION_NAME_DEFINES
uint8_t status; //!< Status of the request
uint16_t arg_len; //!< Parameter length
void * arg; //!< Parameter pointer
} gatt_op_cmp; //!< Value of GATTC_MSG_CMP_EVT
struct {
uint16_t msg_len; //!< GATT message length
uint16_t offset; //!< GATT message data offset
uint8_t *p_msg_data;//!< GATT message data pointer
} gatt_data;
} param;
};
typedef uint16_t (*gatt_msg_handler_t)(struct gatt_msg *p_msg);
typedef struct gatt_uuid {
uint8_t size; //!< Length of UUID (2 or 16 bytes UUIDs: UUID_SIZE_2 or UUID_SIZE_16).
uint8_t p_uuid[16]; //!< Pointer to uuid, could be 2 or 16 bytes array.
}gatt_uuid_t;
typedef struct gatt_attribute {
struct gatt_uuid uuid; //!< Attribute UUID
uint16_t prop; //!< Attribute properties, see @GATT_PROP_BITMAPS_DEFINES
uint16_t max_size; //!< Attribute data maximum size
uint8_t *p_data; //!< Attribute data pointer
}gatt_attribute_t;
typedef struct gatt_service {
const struct gatt_attribute *p_att_tb; //!< Service's attributes table to add to system attribute database.
uint8_t att_nb; //!< Service's attributes number.
gatt_msg_handler_t gatt_msg_handler; //!< Read request callback function.
}gatt_service_t;
typedef struct gatt_client {
const struct gatt_uuid *p_att_tb; //!< Characteristics UUID.
uint8_t att_nb; //!< Characteristic number.
uint8_t att_tb_initialized; //!<
gatt_msg_handler_t gatt_msg_handler; //!< Read request callback function.
}gatt_client_t;
typedef struct gatt_multi_att {
uint8_t length; //The length of each attribute to read, cannot to be 0. The total length should be less than (MTU - 1).
uint16_t handle; //Peer attribute handle
}gatt_multi_att_t;
typedef struct gatt_client_write_param {
uint8_t conidx; //!< Connection index
uint8_t client_id; //!< Client index, this is return value after calling gatt_add_client.
uint8_t att_idx; //!< Attribute index in client uuid table registed when calling gatt_add_client.
uint8_t *p_data; //!< Data pointer to be written
uint16_t data_len; //!< Data length to be written
}gatt_client_write_param_t;
typedef struct gatt_client_write_param_handle {
uint8_t conidx; //!< Connection index
uint8_t client_id; //!< Client index, this is return value after calling gatt_add_client.
uint16_t handle; //!< peer device characteristic handle
uint8_t *p_data; //!< Data pointer to be written
uint16_t data_len; //!< Data length to be written
}gatt_client_write_param_handle_t;
typedef struct gatt_client_read_param {
uint8_t conidx; //!< Connection index
uint8_t client_id; //!< Client index, this is return value after calling gatt_add_client.
uint8_t att_idx; //!< Attribute index in client uuid table registed when calling gatt_add_client.
}gatt_client_read_param_t;
typedef struct gatt_client_read_param_handle {
uint8_t conidx; //!< Connection index
uint8_t client_id; //!< Client index, this is return value after calling gatt_add_client.
uint16_t handle; //!< peer device attribute handle
uint16_t offset; //!< Value offset
}gatt_client_read_param_handle_t;
typedef struct gatt_client_read_param_uuid {
uint8_t conidx; //!< Connection index
uint8_t client_id; //!< Client index, this is return value after calling gatt_add_client.
uint16_t start_hdl; //!< Start handle of the peer specified service, shall be set in the range of 0x0001 - 0xffff
uint16_t end_hdl; //!< End handle of the peer specified service, shall be set in the range of 0x0001 - 0xffff
struct gatt_uuid uuid; //!< Attribute UUID
}gatt_client_read_param_uuid_t;
typedef struct gatt_client_read_multiple_param {
uint8_t conidx; //!< Connection index
uint8_t client_id; //!< Client index, this is return value after calling gatt_add_client.
uint8_t att_nb; //!< Number of attribute to read
gatt_multi_att_t *p_atts; //!< param of multiple read request
}gatt_client_read_multiple_param_t;
typedef struct gatt_client_enable_event {
uint8_t conidx; //!< Connection index
uint8_t client_id; //!< Client index, this is return value after calling gatt_add_client.
uint8_t att_idx; //!< Attribute index in client uuid table registed when calling gatt_add_client.
}gatt_client_enable_event_t;
typedef struct gatt_send_event {
uint8_t conidx; //!< Connection index
uint8_t svc_id; //!< Server index, this is return value after calling gatt_add_server.
uint8_t att_idx; //!< Attribute index in service attribute table registed when calling gatt_add_service.
uint8_t *p_data; //!< Data to be sent as notification.
uint16_t data_len; //!< Data length
}gatt_send_event_t;
typedef struct gatt_send_event_handle {
uint8_t conidx; //!< Connection index
uint8_t svc_id; //!< Server index, this is return value after calling gatt_add_server.
uint16_t handle; //!< Attribute handle
uint8_t *p_data; //!< Data to be sent as notification.
uint16_t data_len; //!< Data length
}gatt_send_event_handle_t;
typedef struct gatt_svc_report {
uint16_t start_hdl; //!< Discovery service start handle
uint16_t end_hdl; //!< Discovery service end handle
struct gatt_uuid uuid; //!< Service UUID
}gatt_svc_report_t;
typedef struct gatt_char_report {
uint16_t char_hdl; //!< characteristic declaration handle
uint16_t val_hdl; //!< characteristic value handle
uint8_t prop; //!< characteristic properties, see ref@GATT_PROP_BITMAPS_DEFINES bit0 - bit7
struct gatt_uuid uuid; //!< characteristic uuid
}gatt_char_report_t;
typedef struct gatt_desc_report {
uint16_t desc_hdl; //!< describtion handle
struct gatt_uuid uuid; //!< describtion uuid
}gatt_desc_report_t;
/* Exported constants --------------------------------------------------------*/
/* Exported macro ------------------------------------------------------------*/
/* Private macros ------------------------------------------------------------*/
/* Exported functions --------------------------------------------------------*/
/*
* @fn gatt_add_service
*
* @brief Addding a services & characteristics into gatt database.
*
* @param[in] p_service : service data to be added.
*
* @return Assigned svc_id.
*/
uint8_t gatt_add_service(struct gatt_service *p_service);
/*
* @fn gatt_delete_user_service
*
* @brief Delete a user-defined services into gatt database.
*
* @param[in] service_id : service id, this is return value after calling gatt_add_service.
*
* @return @ref ble_api_err_t
*/
ble_api_err_t gatt_delete_user_service(uint8_t service_id);
/*
* @fn gatt_delete_gap_gatt_svc
*
* @brief Delete gap and gatt services into gatt database, should be called before adding user service. Can only be called once.
*
* @param[in] None.
*
* @return @ref ble_api_err_t
*/
ble_api_err_t gatt_delete_gap_gatt_svc(void);
/*
* @fn gatt_get_local_svc_hdl
*
* @brief Get the start and end handles of the specified service.
*
* @param[in] service_id : service id, this is return value after calling gatt_add_service.
* @param[in] start_hdl : Pointer to the value of the specified service start handle.
* @param[in] end_hdl : Pointer to the value of the specified service end handle.
*
* @return @ref ble_api_err_t
*/
ble_api_err_t gatt_get_local_svc_hdl(uint8_t service_id, uint16_t *start_hdl, uint16_t *end_hdl);
/*********************************************************************
* @fn gatt_add_client
*
* @brief Addding a GATT client in the system.
*
* @param[in] p_client : client information.
*
* @return Assigned client_id.
*
* @par Sample
* @code
* example1 :
* const struct gatt_uuid client_att_tb[] =
* {
* [0] =
* { UUID_SIZE_16, SPSC_UUID128_ARR_TX},
* [1] =
* { UUID_SIZE_16, SPSC_UUID128_ARR_RX},
* };
* func()
* {
* struct gatt_client client;
* client.p_att_tb = client_att_tb;
* client.att_nb = 2;
* client.gatt_msg_handler = client_msg_handler;
* }
* example2 : //in this case, there will no be uuids being registed.
* func()
* {
* struct gatt_client client;
* client.p_att_tb = NULL;
* client.att_nb = 0;
* client.gatt_msg_handler = client_msg_handler;
* }
* @endcode
*/
uint8_t gatt_add_client(struct gatt_client *p_client);
/*
* @fn gatt_discovery_all_peer_svc
*
* @brief Discover all peer device services.
*
* @param[in] client_id : client index, this is return value after calling gatt_add_client.
* @param[in] conidx : connection index
*
* @return @ref ble_api_err_t.
*/
ble_api_err_t gatt_discovery_all_peer_svc(uint8_t client_id, uint8_t conidx);
/*
* @fn gatt_discovery_peer_svc
*
* @brief Discover assigned peer device service.
*
* @param[in] client_id : client index, this is return value after calling gatt_add_client.
* @param[in] conidx : connection index
* @param[in] uuid : assigned service
*
* @return @ref ble_api_err_t.
*/
ble_api_err_t gatt_discovery_peer_svc(uint8_t client_id, uint8_t conidx, struct gatt_uuid *uuid);
/*
* @fn gatt_discovery_peer_char
*
* @brief Discover peer device characteristic when only the peer specified service handle range is known.
*
* @param[in] client_id : client index, this is return value after calling gatt_add_client.
* @param[in] conidx : connection index
* @param[in] start_hdl : start handle of the peer specified service, shall be set in the range of 0x0001 - 0xffff
* @param[in] end_hdl : end handle of the peer specified service, shall be set in the range of 0x0001 - 0xffff
*
* @return @ref ble_api_err_t.
*/
ble_api_err_t gatt_discovery_peer_char(uint8_t client_id, uint8_t conidx, uint16_t start_hdl, uint16_t end_hdl);
/*
* @fn gatt_discovery_peer_char_by_uuid
*
* @brief Discover peer device characteristic by UUID when only the service handle range is known and the peer specified characteristic UUID is known.
*
* @param[in] client_id : client index, this is return value after calling gatt_add_client.
* @param[in] conidx : connection index
* @param[in] start_hdl : start handle of the peer specified service, shall be set in the range of 0x0001 - 0xffff
* @param[in] end_hdl : end handle of the peer specified service, shall be set in the range of 0x0001 - 0xffff
* @param[in] uuid : uuid of the specified characteristic
*
* @return @ref ble_api_err_t.
*/
ble_api_err_t gatt_discovery_peer_char_by_uuid(uint8_t client_id, uint8_t conidx, uint16_t start_hdl, uint16_t end_hdl, struct gatt_uuid *uuid);
/*
* @fn gatt_discovery_peer_desc
*
* @brief Discover peer device describtion when only the peer specified characteristic handle range is known.
*
* @param[in] client_id : client index, this is return value after calling gatt_add_client.
* @param[in] conidx : connection index
* @param[in] start_hdl : start handle of the peer specified characteristic value handle + 1, shall be set in the range of 0x0001 - 0xffff
* @param[in] end_hdl : end handle of the specified characteristic, shall be set in the range of 0x0001 - 0xffff
*
* @return @ref ble_api_err_t.
*/
ble_api_err_t gatt_discovery_peer_desc(uint8_t client_id, uint8_t conidx, uint16_t start_hdl, uint16_t end_hdl);
/*
* @fn gatt_client_write_req
*
* @brief request write operation with ATT_WRITE_REQUEST
*
* @param[in] write_att : write operation parameter.
*
* @return @ref ble_api_err_t.
*/
ble_api_err_t gatt_client_write_req(struct gatt_client_write_param *write_att);
/*
* @fn gatt_client_write_cmd
*
* @brief request write operation with ATT_WRITE_COMMAND
*
* @param[in] write_att : client information.
*
* @return @ref ble_api_err_t.
*/
ble_api_err_t gatt_client_write_cmd(struct gatt_client_write_param *write_att);
/*
* @fn gatt_cilent_write_req_with_handle
*
* @brief request write operation with ATT_WRITE_REQUEST by handle
*
* @param[in] write_att : client information.
*
* @return @ref ble_api_err_t.
*/
ble_api_err_t gatt_cilent_write_req_with_handle(struct gatt_client_write_param_handle *write_att);
/*
* @fn gatt_cilent_write_cmd_with_handle
*
* @brief request write operation with ATT_WRITE_COMMAND by handle
*
* @param[in] write_att : client information.
*
* @return @ref ble_api_err_t.
*/
ble_api_err_t gatt_cilent_write_cmd_with_handle(struct gatt_client_write_param_handle *write_att);
/*
* @fn gatt_client_read
*
* @brief Read request.
*
* @param[in] read_att : client information.
*
* @return @ref ble_api_err_t.
*/
ble_api_err_t gatt_client_read(struct gatt_client_read_param *read_att);
/*
* @fn gatt_client_read_with_handle
*
* @brief Read request by handle.
*
* @param[in] read_att : client information.
*
* @return @ref ble_api_err_t.
*/
ble_api_err_t gatt_client_read_with_handle(struct gatt_client_read_param_handle *read_att);
/*
* @fn gatt_client_read_with_uuid
*
* @brief Read request by uuid.
*
* @param[in] read_att : client information.
*
* @return @ref ble_api_err_t.
*/
ble_api_err_t gatt_client_read_with_uuid(struct gatt_client_read_param_uuid *read_att);
/*
* @fn gatt_client_read_multiple_with_handle
*
* @brief Read multiple request by handle. Only attribute values that have a known fixed size can be read.
*
* @param[in] read_att : client information.
*
* @return @ref ble_api_err_t.
*/
ble_api_err_t gatt_client_read_multiple_with_handle(struct gatt_client_read_multiple_param *read_att);
/*
* @fn gatt_client_enable_ntf_ind
*
* @brief enable notification or indication.
*
* @param[in] event_enable : client information.
* type : event type.
*
* @return @ref ble_api_err_t.
*/
ble_api_err_t gatt_client_enable_ntf_ind(struct gatt_client_enable_event *event_enable, enum gatt_event_type type);
/*
* @fn gatt_notification
*
* @brief Sending notification.
*
* @param[in] ntf_att : in which service and which attribute the notification will be sent
* This parameter contains servcie ID and attribute ID
* to indicate exact which attribute will be used to send notification.
*
* @return @ref ble_api_err_t.
*/
ble_api_err_t gatt_notification(struct gatt_send_event *ntf_att);
/*
* @fn gatt_notification_with_handle
*
* @brief Sending notification.
*
* @param[in] ntf_att : in which service and which attribute the notification will be sent
* This parameter contains servcie ID and attribute handle
* to indicate exact which attribute will be used to send notification.
*
* @return @ref ble_api_err_t.
*/
ble_api_err_t gatt_notification_with_handle(struct gatt_send_event_handle *ntf_att);
/*********************************************************************
* @fn gatt_indication
*
* @brief Sending indication.
*
* @param[in] ind_att : in which service and which attribute the indication will be sent
* This parameter contains servcie ID and attribute ID
* to indicate exact which attribute will be used to send indication.
*
* @return @ref ble_api_err_t.
*/
ble_api_err_t gatt_indication(struct gatt_send_event *ind_att);
/*********************************************************************
* @fn gatt_indication_with_handle
*
* @brief Sending indication.
*
* @param[in] ind_att : in which service and which attribute the indication will be sent
* This parameter contains servcie ID and attribute handle
* to indicate exact which attribute will be used to send indication.
*
* @return @ref ble_api_err_t.
*/
ble_api_err_t gatt_indication_with_handle(struct gatt_send_event_handle *ind_att);
/*
* @fn gatt_mtu_exchange_req
*
* @brief Exchange MTU with peer device.
*
* @param[in] user_id : client index or service index, this is return value after calling gatt_add_client() or gatt_add_service().
* @param[in] conidx : connection index
* @param[in] mtu :
*
* @return @ref ble_api_err_t.
*/
ble_api_err_t gatt_mtu_exchange_req(uint8_t user_id, uint8_t conidx, uint16_t mtu);
#endif // _GATT_API_H

View File

@ -0,0 +1,45 @@
#ifndef _GATT_DEFINES_H
#define _GATT_DEFINES_H
/// Length of an handle
#define GATT_HANDLE_LEN (2)
/// Length of 16-bit UUID in octets
#define GATT_UUID_16_LEN (2)
/// Length of 32-bit UUID in octets
#define GATT_UUID_32_LEN (4)
/// Length of 128-bit UUID in octets
#define GATT_UUID_128_LEN (16)
/// Length of Database Hash in octets
#define GATT_DB_HASH_LEN (16)
/// GATT UUID Type
enum gatt_uuid_type
{
/// 16-bit UUID value
GATT_UUID_16 = 0x00,
/// 32-bit UUID value
GATT_UUID_32 = 0x01,
/// 128-bit UUID value
GATT_UUID_128 = 0x02,
/// Invalid UUID Type
GATT_UUID_INVALID = 0x03,
};
/// GATT attribute security level
enum gatt_sec_lvl
{
/// Attribute value is accessible on an unencrypted link.
GATT_SEC_NOT_ENC = 0x00,
/// Attribute value is accessible on an encrypted link or modified with using write signed procedure
/// on unencrypted link if bonded using an unauthenticated pairing.
GATT_SEC_NO_AUTH = 0x01,
/// Attribute value is accessible on an encrypted link or modified with using write signed procedure
/// on unencrypted link if bonded using an authenticated pairing.
GATT_SEC_AUTH = 0x02,
/// Attribute value is accessible on an encrypted link or modified with using write signed procedure
/// on unencrypted link if bonded using a secure connection pairing.
GATT_SEC_SECURE_CON = 0x03,
};
#endif // _GATT_DEFINES_H

View File

@ -0,0 +1,300 @@
/**
* Copyright (c) 2019, Freqchip
*
* All rights reserved.
*
*
*/
#ifndef GATT_SIG_UUID_H
#define GATT_SIG_UUID_H
/*********************************************************************
* INCLUDES
*/
#include <stdio.h>
#include <stdint.h>
/*********************************************************************
* CONSTANTS
*/
// SIG UUID size is always 2.
#define ATT_BT_UUID_SIZE 2
/*
* WARNING: The 16-bit UUIDs are assigned by the Bluetooth SIG and published
* in the Bluetooth Assigned Numbers page. Do not change these values.
* Changing them will cause Bluetooth interoperability issues.
*/
/**
* GATT Services
*/
#define GAP_SERVICE_UUID 0x1800 // Generic Access Profile
#define GATT_SERVICE_UUID 0x1801 // Generic Attribute Profile
/**
* GATT Declarations
*/
#define GATT_PRIMARY_SERVICE_UUID 0x2800 // Primary Service
#define GATT_SECONDARY_SERVICE_UUID 0x2801 // Secondary Service
#define GATT_INCLUDE_UUID 0x2802 // Include
#define GATT_CHARACTER_UUID 0x2803 // Characteristic
/**
* GATT Descriptors
*/
#define GATT_CHAR_EXT_PROPS_UUID 0x2900 // Characteristic Extended Properties
#define GATT_CHAR_USER_DESC_UUID 0x2901 // Characteristic User Description
#define GATT_CLIENT_CHAR_CFG_UUID 0x2902 // Client Characteristic Configuration
#define GATT_SERV_CHAR_CFG_UUID 0x2903 // Server Characteristic Configuration
#define GATT_CHAR_FORMAT_UUID 0x2904 // Characteristic Presentation Format
#define GATT_CHAR_AGG_FORMAT_UUID 0x2905 // Characteristic Aggregate Format
#define GATT_VALID_RANGE_UUID 0x2906 // Valid Range
#define GATT_EXT_REPORT_REF_UUID 0x2907 // External Report Reference Descriptor
#define GATT_REPORT_REF_UUID 0x2908 // Report Reference Descriptor
/**
* GATT Characteristics
*/
#define GATT_DEVICE_NAME_UUID 0x2A00 // Device Name
#define GATT_APPEARANCE_UUID 0x2A01 // Appearance
#define GATT_PERI_PRIVACY_FLAG_UUID 0x2A02 // Peripheral Privacy Flag
#define GATT_RECONNECT_ADDR_UUID 0x2A03 // Reconnection Address
#define GATT_PERI_CONN_PARAM_UUID 0x2A04 // Peripheral Preferred Connection Parameters
#define GATT_SERVICE_CHANGED_UUID 0x2A05 // Service Changed
#define GATT_ADDR_RESOL_SUPP 0x2AA6 // Central Address Resolution supported
#define GATT_RSLV_PRIV_ADDR_ONLY 0x2AC9 // Resolvable Private Address only
/*
* WARNING: The 16-bit UUIDs are assigned by the Bluetooth SIG and published
* in the Bluetooth Assigned Numbers page. Do not change these values.
* Changing them will cause Bluetooth interoperability issues.
*/
/**
* GATT Service UUIDs
*/
#define IMMEDIATE_ALERT_SERV_UUID 0x1802 // Immediate Alert
#define LINK_LOSS_SERV_UUID 0x1803 // Link Loss
#define TX_PWR_LEVEL_SERV_UUID 0x1804 // Tx Power
#define CURRENT_TIME_SERV_UUID 0x1805 // Current Time Service
#define REF_TIME_UPDATE_SERV_UUID 0x1806 // Reference Time Update Service
#define NEXT_DST_CHANGE_SERV_UUID 0x1807 // Next DST Change Service
#define GLUCOSE_SERV_UUID 0x1808 // Glucose
#define THERMOMETER_SERV_UUID 0x1809 // Health Thermometer
#define DEVINFO_SERV_UUID 0x180A // Device Information
#define NWA_SERV_UUID 0x180B // Network Availability
#define HEARTRATE_SERV_UUID 0x180D // Heart Rate
#define PHONE_ALERT_STS_SERV_UUID 0x180E // Phone Alert Status Service
#define BATT_SERV_UUID 0x180F // Battery Service
#define BLOODPRESSURE_SERV_UUID 0x1810 // Blood Pressure
#define ALERT_NOTIF_SERV_UUID 0x1811 // Alert Notification Service
#define HID_SERV_UUID 0x1812 // Human Interface Device
#define SCAN_PARAM_SERV_UUID 0x1813 // Scan Parameters
#define RSC_SERV_UUID 0x1814 // Running Speed and Cadence
#define CSC_SERV_UUID 0x1816 // Cycling Speed and Cadence
#define CYCPWR_SERV_UUID 0x1818 // Cycling Power
#define LOC_NAV_SERV_UUID 0x1819 // Location and Navigation
#define IPSS_SERV_UUID 0x1820 // Internet Protocol Support
#define FITMACHINE_SERV_UUID 0x1826 // Fitmachine
/**
* GATT Characteristic UUIDs
*/
#define ALERT_LEVEL_UUID 0x2A06 // Alert Level
#define TX_PWR_LEVEL_UUID 0x2A07 // Tx Power Level
#define DATE_TIME_UUID 0x2A08 // Date Time
#define DAY_OF_WEEK_UUID 0x2A09 // Day of Week
#define DAY_DATE_TIME_UUID 0x2A0A // Day Date Time
#define EXACT_TIME_256_UUID 0x2A0C // Exact Time 256
#define DST_OFFSET_UUID 0x2A0D // DST Offset
#define TIME_ZONE_UUID 0x2A0E // Time Zone
#define LOCAL_TIME_INFO_UUID 0x2A0F // Local Time Information
#define TIME_WITH_DST_UUID 0x2A11 // Time with DST
#define TIME_ACCURACY_UUID 0x2A12 // Time Accuracy
#define TIME_SOURCE_UUID 0x2A13 // Time Source
#define REF_TIME_INFO_UUID 0x2A14 // Reference Time Information
#define TIME_UPDATE_CTRL_PT_UUID 0x2A16 // Time Update Control Point
#define TIME_UPDATE_STATE_UUID 0x2A17 // Time Update State
#define GLUCOSE_MEAS_UUID 0x2A18 // Glucose Measurement
#define BATT_LEVEL_UUID 0x2A19 // Battery Level
#define TEMP_MEAS_UUID 0x2A1C // Temperature Measurement
#define TEMP_TYPE_UUID 0x2A1D // Temperature Type
#define IMEDIATE_TEMP_UUID 0x2A1E // Intermediate Temperature
#define MEAS_INTERVAL_UUID 0x2A21 // Measurement Interval
#define BOOT_KEY_INPUT_UUID 0x2A22 // Boot Keyboard Input Report
#define SYSTEM_ID_UUID 0x2A23 // System ID
#define MODEL_NUMBER_UUID 0x2A24 // Model Number String
#define SERIAL_NUMBER_UUID 0x2A25 // Serial Number String
#define FIRMWARE_REV_UUID 0x2A26 // Firmware Revision String
#define HARDWARE_REV_UUID 0x2A27 // Hardware Revision String
#define SOFTWARE_REV_UUID 0x2A28 // Software Revision String
#define MANUFACTURER_NAME_UUID 0x2A29 // Manufacturer Name String
#define IEEE_11073_CERT_DATA_UUID 0x2A2A // IEEE 11073-20601 Regulatory Certification Data List
#define CURRENT_TIME_UUID 0x2A2B // Current Time
#define SCAN_REFRESH_UUID 0x2A31 // Scan Refresh
#define BOOT_KEY_OUTPUT_UUID 0x2A32 // Boot Keyboard Output Report
#define BOOT_MOUSE_INPUT_UUID 0x2A33 // Boot Mouse Input Report
#define GLUCOSE_CONTEXT_UUID 0x2A34 // Glucose Measurement Context
#define BLOODPRESSURE_MEAS_UUID 0x2A35 // Blood Pressure Measurement
#define IMEDIATE_CUFF_PRESSURE_UUID 0x2A36 // Intermediate Cuff Pressure
#define HEARTRATE_MEAS_UUID 0x2A37 // Heart Rate Measurement
#define BODY_SENSOR_LOC_UUID 0x2A38 // Body Sensor Location
#define HEARTRATE_CTRL_PT_UUID 0x2A39 // Heart Rate Control Point
#define NETWORK_AVAIL_UUID 0x2A3E // Network Availability
#define ALERT_STATUS_UUID 0x2A3F // Alert Status
#define RINGER_CTRL_PT_UUID 0x2A40 // Ringer Control Point
#define RINGER_SETTING_UUID 0x2A41 // Ringer Setting
#define ALERT_CAT_ID_BMASK_UUID 0x2A42 // Alert Category ID Bit Mask
#define ALERT_CAT_ID_UUID 0x2A43 // Alert Category ID
#define ALERT_NOTIF_CTRL_PT_UUID 0x2A44 // Alert Notification Control Point
#define UNREAD_ALERT_STATUS_UUID 0x2A45 // Unread Alert Status
#define NEW_ALERT_UUID 0x2A46 // New Alert
#define SUP_NEW_ALERT_CAT_UUID 0x2A47 // Supported New Alert Category
#define SUP_UNREAD_ALERT_CAT_UUID 0x2A48 // Supported Unread Alert Category
#define BLOODPRESSURE_FEATURE_UUID 0x2A49 // Blood Pressure Feature
#define HID_INFORMATION_UUID 0x2A4A // HID Information
#define REPORT_MAP_UUID 0x2A4B // Report Map
#define HID_CTRL_PT_UUID 0x2A4C // HID Control Point
#define REPORT_UUID 0x2A4D // Report
#define PROTOCOL_MODE_UUID 0x2A4E // Protocol Mode
#define SCAN_INTERVAL_WINDOW_UUID 0x2A4F // Scan Interval Window
#define PNP_ID_UUID 0x2A50 // PnP ID
#define GLUCOSE_FEATURE_UUID 0x2A51 // Glucose Feature
#define RECORD_CTRL_PT_UUID 0x2A52 // Record Access Control Point
#define RSC_MEAS_UUID 0x2A53 // RSC Measurement
#define RSC_FEATURE_UUID 0x2A54 // RSC Feature
#define SC_CTRL_PT_UUID 0x2A55 // SC Control Point
#define CSC_MEAS_UUID 0x2A5B // CSC Measurement
#define CSC_FEATURE_UUID 0x2A5C // CSC Feature
#define SENSOR_LOC_UUID 0x2A5D // Sensor Location
#define CYCPWR_MEAS_UUID 0x2A63 // Cycling Power Measurement
#define CYCPWR_VECTOR_UUID 0x2A64 // Cycling Power Vector
#define CYCPWR_FEATURE_UUID 0x2A65 // Cycling Power Feature
#define CYCPWR_CTRL_PT_UUID 0x2A66 // Cycling Power Control Point
#define LOC_SPEED_UUID 0x2A67 // Location and Speed
#define NAV_UUID 0x2A68 // Navigation
#define POS_QUALITY_UUID 0x2A69 // Position Quality
#define LN_FEATURE_UUID 0x2A6A // LN Feature
#define LN_CTRL_PT_UUID 0x2A6B // LN Control Point
#define GATT_UUID_FITNESS_MACHINE_FEATURE 0x2ACC
#define GATT_UUID_TREADMILL_DATA 0x2ACD //<2F>ܲ<EFBFBD><DCB2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
#define GATT_UUID_CROSS_TRAINER_DATA 0x2ACE //<2F><>Բ<EFBFBD><D4B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
#define GATT_UUID_ROWER_DATA 0x2AD1 //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
#define GATT_UUID_INDOOR_BIKE_DATA 0x2AD2 //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
#define GATT_UUID_STEP_CLIMBER_DATA 0x2ACF //<2F><><EFBFBD>һ<EFBFBD>
#define GATT_UUID_STAIR_CLIMBER_DATA 0x2AD0 //<2F><>¥<EFBFBD>ݻ<EFBFBD>
#define GATT_UUID_TRAINING_STATUS 0x2AD3
#define GATT_UUID_SUPPORT_SPEED_RANGE 0x2AD4
#define GATT_UUID_SUPPORT_INCLINATION_RANGE 0x2AD5
#define GATT_UUID_SUPPORT_RESISTANCE_LEVEL_RANGE 0x2AD6
#define GATT_UUID_SUPPORT_HEART_RATE_RANGE 0x2AD7
#define GATT_UUID_SUPPORT_POWER_RANGE 0x2AD8
#define GATT_UUID_FITNESS_MACHINE_CONTROL_POINT 0x2AD9
#define GATT_UUID_FITNESS_MACHINE_STATUS 0x2ADA
/**
* GATT Unit UUIDs
*/
#define GATT_UNITLESS_UUID 0x2700 // <Symbol>, <Expressed in terms of SI base units>
#define GATT_UNIT_LENGTH_METER_UUID 0x2701 // m, m
#define GATT_UNIT_MASS_KGRAM_UUID 0x2702 // kg, kg
#define GATT_UNIT_TIME_SECOND_UUID 0x2703 // s, s
#define GATT_UNIT_ELECTRIC_CURRENT_A_UUID 0x2704 // A, A
#define GATT_UNIT_THERMODYN_TEMP_K_UUID 0x2705 // K, K
#define GATT_UNIT_AMOUNT_SUBSTANCE_M_UUID 0x2706 // mol, mol
#define GATT_UNIT_LUMINOUS_INTENSITY_C_UUID 0x2707 // cd, cd
#define GATT_UNIT_AREA_SQ_MTR_UUID 0x2710 // m^2, m^2
#define GATT_UNIT_VOLUME_CUBIC_MTR_UUID 0x2711 // m^3, m^3
#define GATT_UNIT_VELOCITY_MPS_UUID 0x2712 // m/s, m s^-1
#define GATT_UNIT_ACCELERATION_MPS_SQ_UUID 0x2713 // m/s^2, m s^-2
#define GATT_UNIT_WAVENUMBER_RM_UUID 0x2714 // ? m^-1
#define GATT_UNIT_DENSITY_KGPCM_UUID 0x2715 // p, kg m^-3
#define GATT_UNIT_SURFACE_DENSITY_KGPSM_UUID 0x2716 // pA, kg m^-2
#define GATT_UNIT_SPECIFIC_VOLUME_CMPKG_UUID 0x2717 // v, m^3 kg^-1
#define GATT_UNIT_CURRENT_DENSITY_APSM_UUID 0x2718 // j, A m^-2
#define GATT_UNIT_MAG_FIELD_STRENGTH_UUID 0x2719 // H, A m
#define GATT_UNIT_AMOUNT_CONC_MPCM_UUID 0x271A // c, mol m^-3
#define GATT_UNIT_MASS_CONC_KGPCM_UUID 0x271B // c, kg m^-3
#define GATT_UNIT_LUMINANCE_CPSM_UUID 0x271C // Lv, cd m^-2
#define GATT_UNIT_REFRACTIVE_INDEX_UUID 0x271D // n, 1
#define GATT_UNIT_RELATIVE_PERMEABLILTY_UUID 0x271E // u, 1
#define GATT_UNIT_PLANE_ANGLE_RAD_UUID 0x2720 // rad, m m-1
#define GATT_UNIT_SOLID_ANGLE_STERAD_UUID 0x2721 // sr, m2 m-2
#define GATT_UNIT_FREQUENCY_HTZ_UUID 0x2722 // Hz, s-1
#define GATT_UNIT_FORCE_NEWTON_UUID 0x2723 // N, m kg s-2
#define GATT_UNIT_PRESSURE_PASCAL_UUID 0x2724 // Pa, N/m2 = m2 kg s-2
#define GATT_UNIT_ENERGY_JOULE_UUID 0x2725 // J, N m = m2 kg s-2
#define GATT_UNIT_POWER_WATT_UUID 0x2726 // W, J/s = m2 kg s-3
#define GATT_UNIT_E_CHARGE_C_UUID 0x2727 // C, sA
#define GATT_UNIT_E_POTENTIAL_DIF_V_UUID 0x2728 // V, W/A = m2 kg s-3 A-1
#define GATT_UNIT_CELSIUS_TEMP_DC_UUID 0x272F // oC, t/oC = T/K - 273.15
#define GATT_UNIT_TIME_MINUTE_UUID 0x2760 // min, 60 s
#define GATT_UNIT_TIME_HOUR_UUID 0x2761 // h, 3600 s
#define GATT_UNIT_TIME_DAY_UUID 0x2762 // d, 86400 s
#define GATT_UNIT_PLANE_ANGLE_DEGREE_UUID 0x2763 // o, (pi/180) rad
#define GATT_UNIT_PLANE_ANGLE_MINUTE_UUID 0x2764 // ', (pi/10800) rad
#define GATT_UNIT_PLANE_ANGLE_SECOND_UUID 0x2765 // '', (pi/648000) rad
#define GATT_UNIT_AREA_HECTARE_UUID 0x2766 // ha, 10^4 m^2
#define GATT_UNIT_VOLUME_LITRE_UUID 0x2767 // l, 10^-3 m^3
#define GATT_UNIT_MASS_TONNE_UUID 0x2768 // t, 10^3 kg
#define GATT_UINT_LENGTH_YARD_UUID 0x27A0 // yd, 0.9144 m
#define GATT_UNIT_LENGTH_PARSEC_UUID 0x27A1 // pc, 3.085678 ?1016 m
#define GATT_UNIT_LENGTH_INCH_UUID 0x27A2 // in, 0.0254 m
#define GATT_UNIT_LENGTH_FOOT_UUID 0x27A3 // ft, 0.3048 m
#define GATT_UNIT_LENGTH_MILE_UUID 0x27A4 // mi, 1609.347 m
#define GATT_UNIT_PRESSURE_PFPSI_UUID 0x27A5 // psi, 6.894757 ?103 Pa
#define GATT_UNIT_VELOCITY_KMPH_UUID 0x27A6 // km/h, 0.2777778 m^s-1
#define GATT_UNIT_VELOCITY_MPH_UUID 0x27A7 // mi/h, 0.44704 m^ s-1
#define GATT_UNIT_ANGULAR_VELOCITY_RPM_UUID 0x27A8 // r/min, 0.1047198 rad s-1
#define GATT_UNIT_ENERGY_GCAL_UUID 0x27A9 //
#define GATT_UNIT_ENERGY_KCAL_UUID 0x27AA // kcal, 4190.02 J
#define GATT_UNIT_ENERGY_KWH_UUID 0x27AB // kWh, 3600000 J
#define GATT_UNIT_THERMODYN_TEMP_DF_UUID 0x27AC // oF, t/oF = T/K ?1.8 - 459.67
#define GATT_UNIT_PERCENTAGE_UUID 0x27AD // %
#define GATT_UNIT_PER_MILE_UUID 0x27AE //
#define GATT_UNIT_PERIOD_BPM_UUID 0x27AF //
#define GATT_UNIT_E_CHARGE_AH_UUID 0x27B0 //
#define GATT_UNIT_MASS_DENSITY_MGPD_UUID 0x27B1 //
#define GATT_UNIT_MASS_DENSITY_MMPL_UUID 0x27B2 //
#define GATT_UNIT_TIME_YEAR_UUID 0x27B3 //
#define GATT_UNIT_TIME_MONTH_UUID 0x27B4 //
/*********************************************************************
* MACROS
*/
#define BUILD_UINT16(loByte, hiByte) \
((uint16_t)(((loByte) & 0x00FF) + (((hiByte) & 0x00FF) << 8)))
#define HI_UINT16(a) (((a) >> 8) & 0xFF)
#define LO_UINT16(a) ((a) & 0xFF)
#define UUID16_ARR(uuid16) {uuid16&0xff,(uuid16&0xff00)>>8}
#define UUID128_ARR(uuid16) {0xFB, 0x34, 0x9B, 0x5F, 0x80, 0x00, 0x00, 0x80, \
0x00, 0x10, 0x00, 0x00, (uuid16 & 0xff),(uuid16&0xff00)>>8, 0x00, 0x00}
/*********************************************************************
* TYPEDEFS
*/
/*********************************************************************
* VARIABLES
*/
#endif /* GATT_SIG_UUID_H */

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,159 @@
#ifndef __L2CAP_API_H
#define __L2CAP_API_H
#include <stdint.h>
#define L2CAP_COC_EVT_SPSM_ADDED 0x00 //!< new SPSM is added
#define L2CAP_COC_EVT_SPSM_REMOVED 0x01 //!< an added SPSM is removed
#define L2CAP_COC_EVT_CONNECTED 0x02 //!< Connection Oriented Channel is created.
#define L2CAP_COC_EVT_MTU_CHANGED 0x03 //!< MTU of created channel is changed
#define L2CAP_COC_EVT_DISCONNECTED 0x04 //!< Created channel is disconnected
#define L2CAP_COC_EVT_DATA_SENT 0x05 //!< data is sent to peer device
#define L2CAP_COC_EVT_CONNECT_REQ 0x06 //!< receive connect request from peer device
#define L2CAP_COC_EVT_DATA_RECV 0x07 //!< receive data from peer device
typedef struct _l2cap_coc_evt {
uint8_t event;
uint8_t status;
union {
/// parameter for L2CAP_COC_EVT_CONNECTED event
struct {
uint8_t conidx; //!< BLE connection index
uint8_t chan_lid; //!< channel link ID of created COC, this field will be useld in
//!< reconfig, disconnect, send data, etc. operation
uint16_t local_rx_mtu;
uint16_t peer_rx_mtu;
} connected;
/// parameter for L2CAP_COC_EVT_MTU_CHANGED event
struct {
uint8_t conidx;
uint8_t chan_lid;
uint16_t local_rx_mtu;
uint16_t peer_rx_mtu;
} mtu_changed;
/// parameter for L2CAP_COC_EVT_DISCONNECTED event
struct {
uint8_t conidx;
uint8_t chan_lid;
uint16_t reason;
} disconnected;
/// parameter for L2CAP_COC_EVT_DATA_SENT event
struct {
uint8_t conidx;
uint8_t chan_lid;
} sent;
/// parameter for L2CAP_COC_EVT_CONNECT_REQ event
struct {
uint16_t token; //!< used in l2cap_coc_conn_cfm to response connection request
uint8_t conidx;
uint8_t nb_chan;
uint16_t spsm;
uint16_t peer_rx_mtu;
} conn_req;
/// parameter for L2CAP_COC_EVT_DATA_RECV event
struct {
uint8_t conidx;
uint8_t chan_lid;
uint16_t status; //!< Error is detected if status is not 0.
uint16_t length;
uint8_t *data;
} data_recv;
} p;
} l2cap_coc_evt_t;
typedef void (*l2cap_coc_evt_cb_t)(l2cap_coc_evt_t *evt);
/*
* @fn l2cap_coc_spsm_new
*
* @brief add new SPSM to l2cap.
*
* @param[in] spsm : new SPSM
* @param[in] sec_lvl : reserved, keep this field to 0
*/
void l2cap_coc_spsm_new(uint16_t spsm, uint8_t sec_lvl);
/*
* @fn l2cap_coc_spsm_delete
*
* @brief remove added SPSM from l2cap.
*
* @param[in] spsm : SPSM to be removed
*/
void l2cap_coc_spsm_delete(uint16_t spsm);
/*
* @fn l2cap_coc_connect
*
* @brief remove added SPSM from l2cap.
*
* @param[in] conidx : BLE connection index
* @param[in] nb_ch : How many channel to create.
* @param[in] spsm : which spsm to connect.
* @param[in] rx_mtu : local RX MTU.
*/
void l2cap_coc_connect(uint8_t conidx, uint8_t nb_ch, uint16_t spsm, uint16_t rx_mtu);
/*
* @fn l2cap_coc_reconfig
*
* @brief used to reset local rx mtu.
*
* @param[in] conidx : BLE connection index
* @param[in] rx_mtu_new : new local RX MTU
* @param[in] nb_ch : how many channel to change MTU
* @param[in] chan_lids : link id of channels to change MTU
*/
void l2cap_coc_reconfig(uint8_t conidx, uint16_t rx_mtu_new, uint8_t nb_ch, uint8_t *chan_lids);
/*
* @fn l2cap_coc_disconnect
*
* @brief disconnect created channel.
*
* @param[in] conidx : BLE connection index
* @param[in] chan_lid : link id of channel to disconnect
*/
void l2cap_coc_disconnect(uint8_t conidx, uint8_t chan_lid);
/*
* @fn l2cap_coc_send_data
*
* @brief used to send data to peer device.
*
* @param[in] conidx : BLE connection index
* @param[in] chan_lid : link id of channel to send data
* @param[in] len : how many data to send, should not be more than peer_rx_mtu
* @param[in] data : storage pointer of sending data
*/
void l2cap_coc_send_data(uint8_t conidx, uint8_t chan_lid, uint16_t len, uint8_t *data);
/*
* @fn l2cap_coc_conn_cfm
*
* @brief used to confirm connect request from peer device.
*
* @param[in] token : used to identify connect request by internal implementation of l2cap, this filed should be
* same with "token" field in L2CAP_COC_EVT_CONNECT_REQ event.
* @param[in] conidx : BLE connection index
* @param[in] nb_chan : how many channels to create
* @param[in] local_rx_mtu : local RX MTU
*/
void l2cap_coc_conn_cfm(uint16_t token, uint8_t conidx, uint8_t nb_chan, uint16_t local_rx_mtu);
/*
* @fn l2cap_coc_init
*
* @brief used to set callback function used for dealing l2cap COC events.
*
* @param[in] cb : ballback function to handle events
*/
void l2cap_coc_init(l2cap_coc_evt_cb_t cb);
#endif // __L2CAP_API_H

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,298 @@
#ifndef __OVERIDE_H
#define __OVERIDE_H
/***************************************************************************
*
* File:
* $Id: overide.h 582 2009-01-20 23:07:22Z gladed $
* $Product: iAnywhere HID SDK v1.x $
* $Revision: 582 $
*
* Description:
* This file contains declarations that are used to override
* the configure options set in config files such as
* btconfig.h. If no overrides are needed then this file
* should be empty. It still must exist.
*
* Created:
* July 15, 1999
*
* Copyright 1999-2004 Extended Systems, Inc. ALL RIGHTS RESERVED.
*
* Unpublished Confidential Information of Extended Systems, Inc.
* Do Not Disclose.
*
* No part of this work may be used or reproduced in any form or by any
* means, or stored in a database or retrieval system, without prior written
* permission of Extended Systems, Inc.
*
* Use of this work is governed by a license granted by Extended Systems,
* Inc. This work contains confidential and proprietary information of
* Extended Systems, Inc. which is protected by copyright, trade secret,
* trademark and other intellectual property rights.
*
****************************************************************************/
/* WARNING: The values in this overide.h file were selected specifically for
* this sample application. If you change them, the sample application may fail
* to compile or not work properly.
*/
#define BT_STACK XA_ENABLED
#define TCP_STACK XA_DISABLED
#define IRDA_STACK XA_DISABLED
#define XA_DEBUG XA_DISABLED
#define HCI_REMOVE_STATIC_BUFFER
#define L2CAP_REMOVE_STATIC_BUFFER
#define RFCOMM_REMOVE_STATIC_BUFFER
#define SDP_REMOVE_STATIC_BUFFER
#define AVRCP_REMOVE_STATIC_BUFFER
#define RADIO_INIT_SIMPLIFY
#define EVM_REPLACE_TIMER
#define RFCOMM_TIMER_OPT XA_ENABLED
/* set default access to non-discover and non-connecte, leave configuration based on pskeys to decide which state will be */
//#define BT_DEFAULT_ACCESS_MODE_NC BAM_GENERAL_ACCESSIBLE
#define BT_DEFAULT_ACCESS_MODE_NC BAM_NOT_SET
#define BT_ALLOW_SCAN_WHILE_CON XA_ENABLED
#define BT_DEFAULT_PAGE_SCAN_WINDOW 0x20
#define BT_DEFAULT_PAGE_SCAN_INTERVAL 0x400
#define BT_DEFAULT_INQ_SCAN_WINDOW 0x20
#define BT_DEFAULT_INQ_SCAN_INTERVAL 0x400
//enable multilink
//#define BT_DEFAULT_ACCESS_MODE_C BAM_GENERAL_ACCESSIBLE
/*
* Set number of devices.
*/
#define NUM_BT_DEVICES 1
#define NUM_KNOWN_DEVICES 8
#define NUM_SCO_CONNS NUM_BT_DEVICES
#define HCI_ALLOW_PRESCAN XA_DISABLED
#define HCI_NUM_EVENTS 8
#define BT_SCO_HCI_DATA XA_ENABLED
/* L2CAP definitions */
#define L2CAP_NUM_PROTOCOLS 10
#define L2CAP_PING_SUPPORT XA_DISABLED
#define BT_PACKET_HEADER_LEN 28 /* Required for MP3 */
#define L2CAP_NUM_CHANNELS 16
//#define L2CAP_NUM_ENHANCED_CHANNELS (NUM_BT_DEVICES*2) // avdtp_stream and avrcp_browsing
#define L2CAP_MTU 1691
//#define L2CAP_MPS 512
#define L2CAP_MANGLER_TESTING XA_DISABLED
#define L2CAP_ENHANCED_IOP_TESTING XA_DISABLED
#define L2CAP_PRELUDE_SIZE 7
#define SDP_SERVER_SEND_SIZE L2CAP_MTU
#define RFCOMM_PROTOCOL XA_ENABLED
#define XA_LOAD_LIST XA_MODULE(AVDTP) XA_MODULE(CMGR) \
XA_MODULE(AVDEV) XA_MODULE(A2DP) \
XA_MODULE(AVRCP) XA_MODULE(HF) \
XA_MODULE(PBAP) XA_MODULE(OBEX) XA_MODULE(GOEP) \
XA_MODULE(HFG)
//#define BT_ALLOW_SCAN_WHILE_CON XA_ENABLED
#define AT_ROLE_TERMINAL XA_ENABLED
#define AT_ROLE_MOBILE XA_ENABLED
#define AT_HEADSET XA_DISABLED
#define AT_HANDSFREE XA_ENABLED
#define AT_PHONEBOOK XA_DISABLED
#define AT_SMS XA_DISABLED
#define AT_DUN XA_DISABLED
#define HF_USE_CALL_MANAGER XA_DISABLED//XA_ENABLED
#define HF_USE_MESSAGING_COMMANDS XA_DISABLED
#define HF_USE_RESP_HOLD XA_DISABLED
#define HF_USE_PHONEBOOK_COMMANDS XA_DISABLED//XA_ENABLED
#define HF_SNIFF_TIMER -1
#define HF_WIDE_BAND_SPEECH XA_ENABLED
#define HCI_NUM_PACKETS 6
/* -------------used to do simplity begin---------------- */
#define HF_USE_IIA XA_DISABLED
#define HF_TX_BUFFER_SIZE 32
#define HF_RECV_BUFFER_SIZE 512
#define HFG_USE_IIA XA_ENABLED
#define HFG_TX_BUFFER_SIZE 256
#define HFG_RECV_BUFFER_SIZE 256
#define HFG_CODEC_NEG XA_DISABLED
/* -------------used to do simplity end----------------- */
// TODO
//#define HF_SDK_FEATURES (HF_FEATURE_CLI_PRESENTATION | \
// HF_FEATURE_VOICE_RECOGNITION | \
// HF_FEATURE_VOLUME_CONTROL)
/* SBC definitions */
#define SBC_ENCODER XA_DISABLED
#define SBC_DECODER XA_DISABLED
/* A2DP definitions */
#define A2DP_SOURCE XA_ENABLED
#define A2DP_SINK XA_ENABLED
/* AVRCP definitions */
#define AVRCP_VERSION_1_3_ONLY XA_DISABLED
#define AVRCP_ADVANCED_TARGET XA_ENABLED
#define AVRCP_ADVANCED_CONTROLLER XA_ENABLED
#define AVRCP_BROWSING_TARGET XA_DISABLED
#define AVRCP_BROWSING_CONTROLLER XA_DISABLED
#define AVRCP_LIST_PLAYERS_ENABLED XA_DISABLED
#ifndef SIMPLIFY_AVRCP
#define AVRCP_ADVANCED_RESPONSE_SIZE 128
#else
#define AVRCP_ADVANCED_RESPONSE_SIZE 32
#endif
/* add by owen. when sniff is enable, accept event for press will not be discard because of timeout */
#define AVRCP_RTX_CMD_TIMEOUT 2000
/* Select the appropriate math operation type */
//#define SBC_MATH_FUNCTIONS SBC_MATH_USE_FIXED_HI_RES
/* #define SBC_MATH_FUNCTIONS SBC_MATH_USE_FIXED_LO_RES */
/* #define SBC_MATH_FUNCTIONS SBC_MATH_USE_FIXED_ASM */
/* #define SBC_MATH_FUNCTIONS SBC_MATH_USE_FLOAT */
#ifdef HID_DEVICE_ENABLE
#define HID_DESCRIPTOR_LEN 0xC6
#define HID_DESCRIPTOR \
0x05, 0x01, \
0x09, 0x06, \
0xa1, 0x01, \
0x85, 0x01, \
0x05, 0x07, \
0x19, 0xe0, \
0x29, 0xe7, \
0x15, 0x00, \
0x25, 0x01, \
0x75, 0x01, \
0x95, 0x08, \
0x81, 0x02, \
0x95, 0x01, \
0x75, 0x08, \
0x81, 0x03, \
0x95, 0x05, \
0x75, 0x01, \
0x05, 0x08, \
0x19, 0x01, \
0x29, 0x05, \
0x91, 0x02, \
0x95, 0x01, \
0x75, 0x03, \
0x91, 0x03, \
0x95, 0x06, \
0x75, 0x08, \
0x15, 0x00, \
0x26, 0xff, 0x00, \
0x05, 0x07, \
0x19, 0x00, \
0x29, 0xff, \
0x81, 0x00, \
0xc0, \
0x05, 0x0c, \
0x09, 0x01, \
0xa1, 0x01, \
0x85, 0x03, \
0x15, 0x00, \
0x25, 0x01, \
0x75, 0x01, \
0x95, 0x1e, \
0x0a, 0x24, 0x02, \
0x0a, 0x25, 0x02, \
0x0a, 0x26, 0x02, \
0x0a, 0x27, 0x02, \
0x0a, 0x21, 0x02, \
0x0a, 0x2a, 0x02, \
0x0a, 0x23, 0x02, \
0x0a, 0x8a, 0x01, \
0x09, 0xe2, \
0x09, 0xea, \
0x09, 0xe9, \
0x09, 0xcd, \
0x09, 0xb7, \
0x09, 0xb6, \
0x09, 0xb5, \
0x0a, 0x83, 0x01, \
0x0a, 0x94, 0x01, \
0x0a, 0x92, 0x01, \
0x0a, 0x09, 0x02, \
0x09, 0xb2, \
0x09, 0xb3, \
0x09, 0xb4, \
0x09, 0x8d, \
0x09, 0x04, \
0x09, 0x30, \
0x0a, 0x07, 0x03, \
0x0a, 0x0a, 0x03, \
0x0a, 0x0b, 0x03, \
0x0a, 0xb1, 0x01, \
0x09, 0xb8, \
0x81, 0x02, \
0x95, 0x01, \
0x75, 0x02, \
0x81, 0x03, \
0xc0, \
0x05, 0x01, \
0x09, 0x80, \
0xa1, 0x01, \
0x85, 0x04, \
0x05, 0x01, \
0x19, 0x81, \
0x29, 0x83, \
0x15, 0x00, \
0x25, 0x01, \
0x95, 0x03, \
0x75, 0x01, \
0x81, 0x06, \
0x95, 0x01, \
0x75, 0x05, \
0x81, 0x01, \
0xc0
#define HID_BATTERY_POWER TRUE
#define HID_REMOTE_WAKE FALSE
#define HID_BOOT_DEVICE FALSE
#endif //#ifdef HID_DEVICE_ENABLE
//#ifdef PBAP_ENABLE
#define OBEX_ROLE_CLIENT XA_ENABLED
#define OBEX_ROLE_SERVER XA_ENABLED
#define OBEX_PACKET_FLOW_CONTROL XA_ENABLED
#define OBEX_HEADER_BUILD XA_ENABLED
#define OBEX_BODYLESS_GET XA_ENABLED
#define OBEX_ALLOW_SERVER_TP_DISCONNECT XA_ENABLED
#define OBEX_DYNAMIC_OBJECT_SUPPORT XA_ENABLED
#define OBEX_SERVER_CONS_SIZE 1
#define OBEX_NUM_TX_PACKETS 2
#define GOEP_DOES_UNICODE_CONVERSIONS XA_ENABLED
#define GOEP_MAX_TYPE_LEN 19
#define PBAP_NUM_SERVERS 0
#define PBAP_NUM_CLIENTS 1
//#endif
#define SPP_SERVER XA_ENABLED
#define SPP_CLIENT XA_ENABLED
#define OEM_STACK XA_DISABLED
#endif /* __OVERIDE_H */

View File

@ -0,0 +1,678 @@
#ifndef _PAN_API
#define _PAN_API
#include "bt_types.h"
#include "me_api.h"
#include "pan_pkt.h"
#define NUM_BNEP_PANUS 1
#define NUM_PAN_ARP_ADDRS 10
#define NUM_BT_PKTS (NUM_BNEP_PANUS * 4)
#define BNEP_ADDR_SIZE BD_ADDR_SIZE
#define BNEP_NUM_TIMERS 3
/*---------------------------------------------------------------------------
* BnepEthernetProtocolType type
*
* Some of the more common Ethernet Protocol types in BNEP packets.
*/
typedef uint16_t BnepEthernetProtocolType;
#define ETHER_TYPE_IPV4 0x0800
#define ETHER_TYPE_ARP 0x0806
#define ETHER_TYPE_IPV6 0x86DD
/*---------------------------------------------------------------------------
* BnepPacketType type
*
* The high order bit of the BNEP packet type is the Extension Flag. The
* one bit Extension Flag indicates if one or more extension headers
* follow the BNEP header before the data payload.
*
*/
typedef uint8_t BnepPacketType;
#define BNEP_GENERAL_ETHERNET 0x00
#define BNEP_CONTROL 0x01
#define BNEP_COMPRESSED_ETHERNET 0x02
#define BNEP_COMPRESSED_ETHERNET_SOURCE_ONLY 0x03
#define BNEP_COMPRESSED_ETHERNET_DEST_ONLY 0x04
/*---------------------------------------------------------------------------
* BnepControlType type
*
*/
typedef uint8_t BnepControlType;
#define BNEP_CONTROL_COMMAND_NOT_UNDERSTOOD 0x00
#define BNEP_SETUP_CONNECTION_REQUEST_MSG 0x01
#define BNEP_SETUP_CONNECTION_RESPONSE_MSG 0x02
#define BNEP_FILTER_NET_TYPE_SET_MSG 0x03
#define BNEP_FILTER_NET_TYPE_RESPONSE_MSG 0x04
#define BNEP_FILTER_MULTI_ADDR_SET_MSG 0x05
#define BNEP_FILTER_MULTI_ADDR_RESPONSE_MSG 0x06
/*---------------------------------------------------------------------------
* PanPacketType type
*
* Indicates the packet type when sending or receiving a data packet.
* All packets include their associated IP header unless otherwise
* indicated.
*/
typedef BnepPacketType PanPacketType;
/* Packet type unknown.
*/
#define PANPKT_UNKNOWN 0x40
/* Packet type is General Ethernet and includes the MAC header. The packet
* must be parsed to determine higher layer protocols. This packet is
* normally forwarded to the remote network.
*/
#define PANPKT_ETHER_PKT 0x41
/* Packet is an ARP request.
*/
#define PANPKT_ARP_REQUEST 0x42
/* Packet is an ARP reply.
*/
#define PANPKT_ARP_REPLY 0x43
/* Packet type is IP.
*/
#define PANPKT_IP 0x44
/* Packet is an ICMP request (Ping echo.)
*/
#define PANPKT_ICMP_REQUEST 0x45
/* Packet is an ICMP reply (Ping echo reply.)
*/
#define PANPKT_ICMP_REPLY 0x46
/* Packet type is TCP.
*/
#define PANPKT_TCP 0x47
/* Packet type is UDP.
*/
#define PANPKT_UDP 0x48
/* Packet is a DHCP request.
*/
#define PANPKT_DHCP_REQUEST 0x49
/* Packet is a DHCP reply.
*/
#define PANPKT_DHCP_REPLY 0x4a
/* Packet is a BNEP network filter (no IP header.)
*/
#define PANPKT_NET_FILTER 0x4b
/* Packet is a BNEP multicast filter (no IP header.)
*/
#define PANPKT_MCAST_FILTER 0x4c
/* End of PanPacketType */
#define ETHER_HDR_SIZE (BNEP_ADDR_SIZE*2 + sizeof(BnepEthernetProtocolType))
#define ETHER_RANGE_SIZE (sizeof(BnepEthernetProtocolType)*2)
#define BNEP_TYPE_SIZE sizeof(BnepPacketType)
#define BNEP_GNRL_HDR_SIZE (BNEP_TYPE_SIZE + ETHER_HDR_SIZE)
#define BNEP_CONTROL_TYPE_SIZE sizeof(BnepControlType)
#define BNEP_CONTROL_HDR_SIZE (BNEP_TYPE_SIZE + BNEP_CONTROL_TYPE_SIZE)
#define PAN_PANU_NUM_ATTRIBUTES 9
#define PAN_GN_NUM_ATTRIBUTES 11
#define PAN_NAP_NUM_ATTRIBUTES 13
#define PAN_NUM_SEARCH_ATTRIBUTES 21
/*---------------------------------------------------------------------------
* BnepFilterResponseMsg type
*
*/
typedef uint16_t BnepFilterResponseMsg;
#define BNEP_FR_OPERATION_SUCCESS 0x0000
#define BNEP_FR_UNSUPPORTED 0x0001
#define BNEP_FR_INVALID_PROTOCOL 0x0002
#define BNEP_FR_FAILED_MAX_FILTERS 0x0003
#define BNEP_FR_FAILED_SECURITY 0x0004
/** Indicates an open request is in progress on a client. Use
* PAN_SetupConnection to complete the connection with a BNEP Setup
* Connection control message. This event precedes the PANEVENT_OPEN
* event on a client.
*/
#define PANEVENT_SETUP_CONNECTION 0x81
/** Indicates an open request on a server. Use PAN_ControlResponse to
* complete the connection with a BNEP Setup Connection response. This
* event will follow a PANEVENT_OPEN event on a server.
*/
#define PANEVENT_SETUP_CONN_REQ 0x82
/** Indicates a BNEP control packet other than SETUP_CONNECTION has been
* received.
*/
#define PANEVENT_CONTROL_IND 0x83
/** Indicates an Open request is in progress on a server or complete on
* a client.
*/
#define PANEVENT_OPEN 0x87
/** Indicates the connection is closed.
*/
#define PANEVENT_CLOSED 0x88
/** Indicates an SDP service query failed on an open.
*/
#define PANEVENT_SDP_FAILED 0x89
/** Indicates a data packet is available. The parms.pkt parameter points
* to the packet. The packet is of type PanPacketType indicated in the
* parms.type parameter. The packet length is indicated in the
* parms.rxPktLen parameter.
*/
#define PANEVENT_DATA_IND 0x8a
/** Indicates the PanPacket used to send data has been released and may
* be freed or reused.
*/
#define PANEVENT_DATA_HANDLED 0x8b
/* End of PanEvent */
#define PANBTPKT_FREE 0
#define PANBTPKT_INUSE 1
#define PANBTPKT_INUSE_INT 2
#define PANBTPKT_INUSE_EXT 3
/* Forward reference to PanCallbackParms defined below */
typedef struct _PanCallbackParms PanCallbackParms;
/*---------------------------------------------------------------------------
* PanCallback type
*
* PAN Events and data are passed to the application through a callback
* function of this type defined by the application.
*/
typedef void (*PanCallback)(PanCallbackParms *parms);
/*---------------------------------------------------------------------------
* BNEP_ADDR structure
*
* Represents a 48-bit Bluetooth or Ethernet device address.
*/
typedef struct _BNEP_ADDR
{
uint8_t addr[BNEP_ADDR_SIZE];
} BNEP_ADDR;
/*---------------------------------------------------------------------------
* BnepPanu structure
*
* Maintains connection information for a PANU channel.
*/
typedef struct _BnepPanu {
BNEP_ADDR bnepAddr; /* BNEP_ADDR of remote device */
uint16_t l2ChannelId; /* L2CAP channel ID for connection */
uint8_t state; /* PANU state */
BtRemoteDevice *remDev; /* Remote device of connection */
EvmTimer timer[BNEP_NUM_TIMERS]; /* Timers for Control commands */
uint32_t controlTimeout; /* Timeout value for Control commands */
} BnepPanu;
/*----------------------------------------------------------------------
* PanService structure
*
* PAN service registration structure used to register a service
* through the PAN_Register function.
*/
typedef struct _PanService {
PanCallback callback;
uint16_t type;
} PanService;
/* End of PanService */
/*----------------------------------------------------------------------
* PanPacket structure
*
* PAN Packet allocation structure.
*/
typedef struct _PanPacket {
uint8_t header[BNEP_GNRL_HDR_SIZE];
uint8_t body[];
} PanPacket;
/* End of PanPacket */
/* ---------------------------------------------------------------------------
* BtPacket container
*/
typedef struct _PanBtPkt
{
uint16_t context;
BtPacket btPkt;
} PanBtPkt;
/*----------------------------------------------------------------------
* PanSetupConnPkt structure
*
* PAN Setup Connection Request allocation structure.
*/
typedef struct _PanSetupConnPkt {
uint8_t header[BNEP_CONTROL_HDR_SIZE];
uint8_t uuidSize;
uint8_t dstUuid[2];
uint8_t srcUuid[2];
} PanSetupConnPkt;
/* End of PanSetupConnPkt */
/*----------------------------------------------------------------------
* PanControlRespPkt structure
*
* PAN Control response message allocation structure.
*/
typedef struct _PanControlRespPkt {
uint8_t header[BNEP_CONTROL_HDR_SIZE];
uint8_t message[2];
} PanControlRespPkt;
/* End of PanControlRespPkt */
/*---------------------------------------------------------------------------
* PanRecvCb type
*
* Describes the PAN Receive data callback function. Used when user decide to
* deal receicved data from remote device directly.
*/
typedef void (* PanRecvCb)(uint8_t *, uint16_t);
/* End of PanRecvCb */
/*--------------------------------------------------------------------------
* PanUser structure
*
* Maintains PANU connection info and status during an application
* session. A NAP, GN or PANU uses this structure to maintain
* information on connected PANU(s). The PanUser structure is always
* allocated by the application and is passed into the SDK through
* the PAN_Open function by a client or the PAN_Listen function by a
* server.
*/
typedef struct _PanUser {
/* === Internal use only === */
BnepPanu bnepPanu; /* remote BnepPanu */
BNEP_ADDR destMac; /* storage for dest MAC address */
uint8_t state;
PanRecvCb recv_cb; /* callback for receive data */
/* NAP */
uint32_t remIpAddr;
uint32_t remAddrContext;
/* SDP Client */
uint16_t dstService;
SdpQueryToken sdpQueryToken;
uint8_t sdpSrchAttrib[PAN_NUM_SEARCH_ATTRIBUTES];
} PanUser;
/* End of PanUser */
/*---------------------------------------------------------------------------
* PanCallbackParms structure
*
* Describes a callback event and any data that relates to the event.
*/
typedef struct _PanCallbackParms
{
/* Completion status based on the event type. Reason will be
* L2capDiscReason for PANEVENT_CLOSED events or BtStatus for others.
*/
uint16_t status;
uint8_t event; /* Type of PANEVENT_XX event */
/* Handle to the PanUser structure associated with this event. Valid
* after a connection is established.
*/
PanUser *pan;
/* Type of packet associated with this event. Valid on
* PANEVENT_DATA_HANDLED and PANEVENT_DATA_IND events.
*/
uint8_t type;
/* On PANEVENT_DATA_HANDLED event, points to the sent data packet.
* On PANEVENT_DATA_IND event, points to the received packet.
* The PanPacketType field above indicates the type.
*/
uint8_t *pkt;
/* Length of received data packet. Valid on
* PANEVENT_DATA_IND events.
*/
uint16_t rxPktLen;
} PanCallbackParmsT;
/* End of PanCallbackParms */
/*---------------------------------------------------------------------------
* bnep_addr_ntoa()
*
* Convert a MSB BNEP_ADDR to MSB ASCII notation aa:bb:cc:dd:ee:ff.
* AddrString should point to no less than 20 bytes. It will be
* null-terminated upon return.
*
* Parameters:
* bnepAddr - Pointer to BNEP_ADDR to convert.
* addrString - Pointer to storage for the converted BNEP address string.
*
* Returns:
* pointer to the converted/provided AddrString
*/
char *bnep_addr_ntoa(const BNEP_ADDR *bnepAddr, char *addrString);
/*---------------------------------------------------------------------------
* BNEP_Init()
*
* Initializes the BNEP layer.
*
* Returns:
* TRUE - BNEP was successfully initialized.
*
* FALSE - BNEP failed to initialize. This can
* happen when BNEP cannot be registered with L2CAP.
*/
int BNEP_Init(void);
/*---------------------------------------------------------------------------
* PAN_Init()
*
* Initialize PAN. This should be the first function called for PAN.
*
* Returns:
* TRUE - PAN was successfully initialized.
* FALSE - PAN failed to initialize.
*/
int PAN_Init(void);
/*---------------------------------------------------------------------------
* PAN_Register()
*
* Register a callback for events associated with the PanService. An
* application may register for only one service in a session.
*
* Parameters:
* service - pointer to PanService structure with the PanCallback and
* PanServiceType fields initialized for the desired service.
*
* Returns:
* BT_STATUS_SUCCESS - The registration succeeded.
*
* BT_STATUS_FAILED - The registration failed.
*/
BtStatus PAN_Register(PanService *service);
/*---------------------------------------------------------------------------
* PAN_Open()
*
* Initiate an open request for a PAN service connection.
*
* Parameters:
* remDev - The target remote device for the connection.
* pan - handle to the PanUser structure used to maintain the
* connection.
* cb - callback function used to handle received data directly
* tgtService - Service required for the connection.
*
* Returns:
* BT_STATUS_PENDING - The open request succeeded.
*
* BT_STATUS_FAILED - The open request failed.
*/
BtStatus PAN_Open(BtRemoteDevice *remDev, PanUser *pan, PanRecvCb cb, uint16_t tgtService);
/*---------------------------------------------------------------------------
* PAN_SetupConnection()
*
* Send a BNEP Setup Connection message from a client to complete an
* open connection request.
*
* Parameters:
* pan - handle to the PanUser structure used to maintain the
* connection.
* setupPkt - Setup connection packet.
*
* Returns:
* BT_STATUS_PENDING - The send succeeded. (If accepted by the remote
* device, a PANEVENT_OPEN event will occur.)
*
* BT_STATUS_FAILED - The send failed.
*/
BtStatus PAN_SetupConnection(PanUser *pan, PanSetupConnPkt *setupPkt);
/*---------------------------------------------------------------------------
* PAN_ControlResponse()
*
* Send a BNEP Setup Connection message from a server to complete an
* open connection request.
*
* Parameters:
* pan - handle to the PanUser structure used to maintain the
* connection.
* type - BNEP Control response type.
* controlRespPkt - control response packet.
*
* Returns:
* BT_STATUS_PENDING - The send succeeded.
*
* BT_STATUS_FAILED - The send failed.
*/
BtStatus PAN_ControlResponse(PanUser *pan, BnepControlType type,
PanControlRespPkt *controlRespPkt);
/*---------------------------------------------------------------------------
* PAN_ForwardPkt()
*
* Forward a data packet received from the BNEP protocol stack. The
* packet must include the Ethernet MAC header. No PANEVENT_DATA_HANDLED
* event will follow this function, as it was received from the BNEP
* stack and does not require allocation from the application memory
* pool.
*
* Parameters:
* pan - handle to the PanUser structure used to maintain the
* connection.
* pkt - pointer to the Ethernet data packet received from the BNEP
* stack.
* len - length of data packet.
*
* Returns:
* BT_STATUS_PENDING - The send succeeded.
*
* BT_STATUS_FAILED - The send failed.
*/
BtStatus PAN_ForwardPkt(PanUser *pan, uint8_t *pkt, uint16_t len);
/*---------------------------------------------------------------------------
* PAN_Close()
*
* Close the connection associated with the PanUser structure.
*
* Parameters:
* pan - handle to the PanUser structure used to maintain the
* connection.
*
* Returns:
* BT_STATUS_SUCCESS - The close succeeded.
*
* BT_STATUS_FAILED - The close failed.
*/
BtStatus PAN_Close(PanUser *pan);
/*---------------------------------------------------------------------------
* PAN_SendPkt()
*
* Send a data packet created by the application. A PANEVENT_DATA_HANDLED
* will be sent to the registered callback to notify when the
* packet can be returned to the memory pool.
*
* Parameters:
* pan - handle to the PanUser structure used to maintain the
* connection.
* panPkt - pointer to the data packet encapsulated in the PanPacket
* structure.
* type - data packet type.
* len - length of data packet.
*
* Returns:
* BT_STATUS_PENDING - The send succeeded.
*
* BT_STATUS_FAILED - The send failed.
*/
BtStatus PAN_SendPkt(PanUser *pan, PanPacket *panPkt, PanPacketType type, uint16_t len);
/*---------------------------------------------------------------------------
* PAN_SendArp()
*
* Send an ARP to resolve the specified IP address to a MAC address.
*
* Parameters:
* pan - handle to the PanUser structure associated with this address.
* destIP - IP address to resolve to a MAC address.
*
* Returns:
* The MAC address in a BNEP_ADDR structure.
*/
BNEP_ADDR *PAN_SendArp(PanUser *pan, uint32_t destIP);
/*---------------------------------------------------------------------------
* PAN_MakeArpHdr()
*
* Helper function to build an ARP header.
*
* Parameters:
* arpHdr - pointer to memory buffer large enough for ARP header.
* dstIP - IP address of destination.
*
* Returns:
* BT_STATUS_SUCCESS - The operation succeeded.
*
* BT_STATUS_FAILED - The operation failed.
*/
BtStatus PAN_MakeArpHdr(ArpHeader *arpHdr, uint32_t dstIP);
/*---------------------------------------------------------------------------
* PAN_GetLocalIpAddr_v2()
*
* Get the local IP address.
*
* Parameters:
* None
*
* Returns:
* The local IP address as an uint32_t.
*/
uint32_t PAN_GetLocalIpAddr_v2(void);
/*---------------------------------------------------------------------------
* PAN_SetLocalIpAddr_v2()
*
* Set the local IP address.
*
* Parameters:
* addr - local IP address.
*
* Returns:
* None.
*/
void PAN_SetLocalIpAddr_v2(uint32_t addr);
/*---------------------------------------------------------------------------
* PAN_GetRemoteIpAddr_v2()
*
* Get the remote IP address.
*
* Parameters:
* pan - handle to the PanUser structure used to maintain the
* connection.
*
* Returns:
* The remote IP address as an uint32_t.
*/
uint32_t PAN_GetRemoteIpAddr_v2(PanUser *pan);
/*---------------------------------------------------------------------------
* PAN_SetRemoteMacAddr()
*
* Set the MAC address of the remote PAN device.
*
* Parameters:
* pan - handle to the PanUser structure used to maintain the
* connection.
* macAddr - MAC address of remote PAN device.
*
* Returns:
* BT_STATUS_SUCCESS - The registration succeeded.
*
* BT_STATUS_FAILED - The registration failed.
*/
BtStatus PAN_SetRemoteMacAddr(PanUser *pan, uint8_t *macAddr);
/*---------------------------------------------------------------------------
* PAN_SetDhcpAddr_v2()
*
* Set the address to use for DHCP requests.
*
* Parameters:
* addr - DHCP address to use.
*
* Returns:
* None.
*/
void PAN_SetDhcpAddr_v2(uint32_t addr);
/*---------------------------------------------------------------------------
* PanFindFreeBtPkt()
*---------------------------------------------------------------------------
*
* Synopsis: Find available packet.
*
* Return: packet pointer or 0.
*/
PanBtPkt *PanFindFreeBtPkt(void);
/*---------------------------------------------------------------------------
* BNEP_SendPkt()
*
* Send a BNEP packet to the remote device. The bnepPkt parameter
* points to one of the valid BNEP packet types: General, Compressed,
* Source only compressed or Destination only compressed and may
* contain extension headers.
*
* Parameters:
* panu - Identifies the BNEP PANU channel that owns the packet.
* btPacket - A pointer to the BtPacket used to send the BNEP packet
* through L2CAP.
* bnepPkt - A pointer to the BNEP packet to send.
* bnepPktLen - Length of the BNEP packet.
*
* Returns:
* BT_STATUS_PENDING - The send packet process has been successfully
* started.
*
* BT_STATUS_INVALID_PARM - An invalid parameter was used.
*
* BT_STATUS_FAILED - L2CAP_Send failure.
*
* BT_STATUS_IN_PROGRESS - BNEP is busy sending another packet.
*/
BtStatus BNEP_SendPkt(BnepPanu *panu,
BtPacket *btPacket,
uint8_t *bnepPkt,
uint16_t bnepPktLen);
#endif // _PAN_API

View File

@ -0,0 +1,167 @@
#ifndef __PAN_PKT_H
#define __PAN_PKT_H
/*****************************************************************************
*
* File:
* $Id: pan_pkt.h 1284 2009-04-08 22:49:58Z suneelk $
* $Product: iAnywhere PAN SDK v1.x $
* $Revision: 1284 $
*
* Description: This file contains code for the PAN profile.
*
* Created: Feb 7, 2003
*
* Copyright 2000-2004 Extended Systems, Inc. ALL RIGHTS RESERVED.
* Portions copyright 2005-2008 iAnywhere Solutions, Inc.
*
* Unpublished Confidential Information of iAnywhere Solutions, Inc.
* Do Not Disclose.
*
* No part of this work may be used or reproduced in any form or by any means,
* or stored in a database or retrieval system, without prior written
* permission of iAnywhere Solutions, Inc.
*
* Use of this work is governed by a license granted by iAnywhere Solutions, Inc.
* This work contains confidential and proprietary information of iAnywhere
* Solutions, Inc. which is protected by copyright, trade secret, trademark and
* other intellectual property rights.
*
****************************************************************************/
#define IPPROTO_IP 0 /* dummy for IP */
#define IPPROTO_ICMP 1 /* Control Message Protocol */
#define IPPROTO_IPV4 4 /* IPv4 */
#define IPPROTO_TCP 6 /* TCP */
#define IPPROTO_UDP 17 /* UDP */
#define NET_PROTOCOL_TYPE_ARP 0x0806 /* Address Resolution Protocol */
#define NET_PROTOCOL_TYPE_VLAN 0x8100 /* VLAN( Virtual lan)-tagged frame (IEEE 802.1Q)*/
#define NET_PROTOCOL_TYPE_IPV4 0x0800 /* Internet Protocol, Version 4 (IPv4)*/
#define ICMP_ECHO 8
#define ICMP_ECHOREPLY 0
#define ICMP_MIN 8 /* minimum icmp packet size (just header) */
#define BOOTP_SERVER 0x0043
#define BOOTP_CLIENT 0x0044
#define DHCPDISCOVER 1
#define DHCPOFFER 2
#define DHCPREQUEST 3
#define DHCPDECLINE 4
#define DHCPACK 5
#define DHCPNAK 6
#define DHCPRELEASE 7
/* ---------------------------------------------------------------------------
* ARP header
*/
typedef __PACKED_STRUCT _ArpHeader {
uint16_t macType; /* MAC address type */
uint16_t protoType; /* Protocol address type */
uint8_t macLen; /* MAC address length */
uint8_t protoLen; /* Protocol address length */
uint16_t op; /* ARP operation (1=request, 2=reply) */
uint8_t srcMac[6]; /* MAC source address */
uint32_t srcIP; /* IP source address */
uint8_t dstMac[6]; /* MAC destination address */
uint32_t dstIP; /* IP destination address */
} ArpHeader;
/* ---------------------------------------------------------------------------
* IP header
*/
typedef __PACKED_STRUCT _IpHeader {
uint32_t srcIP; /* source address */
uint32_t dstIP; /* destination address */
uint8_t hdrLen:4; /* length of the header in 32 bit units */
uint8_t version:4; /* Version of IP */
uint8_t tos; /* Type of service */
uint16_t totalLen; /* total length of the packet */
uint16_t id; /* unique identifier */
uint16_t offset; /* fragment offset */
uint8_t ttl; /* time to live */
uint8_t proto; /* protocol (TCP, UDP etc) */
uint16_t cksum; /* IP checksum */
} IpHeader;
/* ---------------------------------------------------------------------------
* ICMP header
*/
typedef __PACKED_STRUCT _IcmpHeader {
uint8_t type;
uint8_t code; /* type sub code */
uint16_t cksum;
uint16_t id;
uint16_t seq;
uint32_t timestamp; /* Timestamp at the beginning of data */
} IcmpHeader;
/* ---------------------------------------------------------------------------
* UDP header
*/
typedef __PACKED_STRUCT _UdpHeader {
uint16_t srcPort; /* Source port # */
uint16_t dstPort; /* Destination port # */
uint16_t len; /* Udp packet length */
uint16_t cksum; /* Udp checksum (optional) */
} UdpHeader;
/* ---------------------------------------------------------------------------
* DHCP header
*/
typedef __PACKED_STRUCT _DhcpHeader {
uint8_t op;
uint8_t htype;
uint8_t hlen;
uint8_t hops;
uint32_t xid;
uint16_t secs;
uint16_t flags;
uint32_t ciaddr;
uint32_t yiaddr;
uint32_t siaddr;
uint32_t giaddr;
uint8_t chaddr[16];
uint8_t sname[64];
uint8_t file[128];
uint8_t cookie[4];
uint8_t options[312];
} DhcpHeader;
/* ---------------------------------------------------------------------------
* TCP header
*/
typedef __PACKED_STRUCT _TcpHeader {
uint16_t srcPort; /* Source port # */
uint16_t dstPort; /* Destination port # */
uint32_t seq;
uint32_t ack;
uint8_t reserved:4; /* reserved */
uint8_t offset:4; /* length of the header, in 32 bit units */
uint8_t flags;
uint16_t window;
uint16_t cksum; /* calculated from TCP Pseudo Header */
uint16_t urgent;
uint8_t options[];
/* 0 to 44 bytes of options may be placed at the end of the TCP header.
* The options must be padded to make the TCP header length a multiple
* of 32 bits.
*/
} TcpHeader;
/* ---------------------------------------------------------------------------
* TCP Pseudo header (used for checksum calculation)
*/
typedef __PACKED_STRUCT _TcpPseudoHeader {
uint32_t srcIP; /* Source IP address */
uint32_t dstIP; /* Destination IP address */
uint8_t zero;
uint8_t proto; /* IP protocol */
uint16_t len; /* totoal length */
} TcpPseudoHeader;
#endif /* __PAN_PKT_H */

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,152 @@
#ifndef __RFCOMM_API_H
#define __RFCOMM_API_H
#include "btconfig.h"
#include "me_api.h"
#include "sec_api.h"
typedef struct _RfDeferEvent {
ListEntry node;
void *func;
void *channel;
} RfDeferEvent;
/*---------------------------------------------------------------------------
* RfChannel structure
*
* Represents a single RFCOMM channel. The RFCOMM user must create
* this structure and fill in the "callback", "maxFrameSize", and
* "priority" fields prior to calling RF_OpenClientChannel. Only the
* "callback" filed must be set when calling RF_RegisterServerChannel.
*/
typedef struct _RfChannel
{
ListEntry node; /* Used internally by RFCOMM. */
/* Callback function for channel events */
void* callback;
/* Frame size for the channel. This value must be between
* RF_MIN_FRAME_SIZE and RF_MAX_FRAME_SIZE.
*/
uint16_t maxFrameSize;
/* Priority of the channel. Channels with higher priority have smaller
* "priority" values. Generally, data on higher priority channels is
* sent before lower priority channels. The priority must be between
* RF_DEFAULT_PRIORITY (0) and RF_LOWEST_PRIORITY (63).
*/
uint8_t priority;
/* User context. In some environments the context of the application
* during a callback is not known. In these cases, a pointer to the
* application's context can be stored in userContext and then
* retrieved during the callback.
*/
void *userContext;
/* === Internal use only === */
BtSecurityToken secToken;
uint8_t state;
uint8_t muxId;
uint8_t dlcId;
uint8_t dlci;
uint16_t flags;
ListEntry txQueue;
EvmTimer timer;
uint8_t cmdSent;
uint8_t rfSignals;
int16_t rxCredit;
uint16_t txCredit;
uint8_t grantedCredit;
uint8_t initialRxCredit;
uint16_t initialFrameSize;
RfDeferEvent deferEvent;
}RfChannel;
typedef uint8_t RfSignals;
/*---------------------------------------------------------------------------
* RfModemStatus structure
*
* Represents the status of V.24 signals. To send signals on a connection,
* create and fill in this structure, then call RF_SetModemStatus.
*
* When the remote device sends these signals, RFCOMM generates an
* RFEVENT_MODEM_STATUS_IND event. During this event, you can read the
* status in the RfCallbackParms "ptrs.modemStatus" field.
*/
typedef struct _RfModemStatus
{
RfSignals signals; /* Contains all signals that apply to this status
* message.
*/
uint8_t breakLen; /* Indicates the length of the break signal in 200 ms
* units. If 0, no break signal was sent. Must be
* between 0 and 15 (inclusive).
*/
} RfModemStatus;
typedef uint8_t RfLineStatus;
typedef uint8_t RfBaudRate;
typedef uint8_t RfDataFormat;
typedef uint8_t RfFlowControl;
typedef uint16_t RfPortSettingsMask;
/*---------------------------------------------------------------------------
* RfPortSettings structure
*
* Represents port settings for an RFCOMM channel. Port settings
* are used for RS232 emulation. They are informational and have
* no real effect on the data stream at the RFCOMM level. To change
* port settings for a channel, this structure is filled and provided
* to RFCOMM using the RF_RequestPortSettings function.
*
* When the remote device changes port settings, RFCOMM provides
* this structure along with the RFEVENT_PORT_NEG_IND event. The
* RFCOMM user can then review the settings, then accept or reject
* them with RF_AcceptPortSettings.
*
* Fields in this structure may be valid or invalid, depending on
* the contents of the "parmMask" field.
*/
typedef struct _RfPortSettings
{
RfBaudRate baudRate; /* Indicates the baud rate */
RfDataFormat dataFormat; /* Contains data bits, stop bits, and
* parity settings.
*/
RfFlowControl flowControl; /* Indicates port flow control options */
uint8_t xonChar; /* Indicates the XON character */
uint8_t xoffChar; /* Indicates the XOFF character */
/* Contains a bitmask of settings.
*
* When changing port settings with RF_RequestPortSettings, "parmMask"
* indicates which port settings are being changed.
*
* During an RFEVENT_PORT_NEG_IND event, "parmMask" describes which
* parameters the remote device sent.
*/
RfPortSettingsMask parmMask;
} RfPortSettings;
typedef struct _RfService
{
/* Identifies the ID that corresponds to this service. This ID value
* can be set to 0 before this structure is used if the desired RFCOMM
* Server ID not known. If it is set to 0, then, after the service has been
* registered with RFCOMM, it will contain a valid RFCOMM Server ID. If
* the desired RFCOMM Server ID is known, then this ID value can be set to
* that value before registering with RFCOMM. In either case, make sure to
* register this ID with SDP so that remote devices can locate this RFCOMM
* service. This ID can also be used as the channel in * BtSecurityRecords
* (for incoming connections only).
*/
uint8_t serviceId;
} RfService;
#endif

View File

@ -0,0 +1,78 @@
#ifndef __SDP_API_H
#define __SDP_API_H
#include "bt_types.h"
#include "me_api.h"
typedef uint16_t SdpAttributeId;
/*---------------------------------------------------------------------------
* SdpAttribute structure
*
* Defines an attribute's ID and value. SdpAttribute structures
* are stored in a SdpRecord prior to calling the SDP_AddRecord
* function.
*/
typedef struct _SdpAttribute
{
SdpAttributeId id; /* Attribute ID. */
uint16_t len; /* Length of the value buffer */
const uint8_t *value; /* An array of bytes that contains the value
* of the attribute. The buffer is in
* Data Element form (see SdpDataElemType
* and SdpDataElemSize).
*/
/* Group: The following field is for internal use only */
uint16_t flags;
} SdpAttribute;
/*---------------------------------------------------------------------------
* SdpRecord structure
*
* Defines the contents of a service record. Service records are
* initialized and provided to SDP_AddRecord.
*/
typedef struct _SdpRecord
{
ListEntry node; /* For internal use only. */
uint8_t num; /* Total number of attributes in "attribs". */
/* Pointer to an array of attributes.
*
* Store the attributes in ascending order by attribute ID, and
* do not add two attributes with the same ID.
*
* Do not include an AID_SERVICE_RECORD_HANDLE attribute. This
* attribute is handled automatically by SDP.
*/
SdpAttribute *attribs;
/* The service class fields of the class of device. Use the values defined
* in me.h. The device class portion is ignored.
*/
BtClassOfDevice classOfDevice;
/* Group: The following fields are for internal use only. */
uint32_t handle; /* Service Record Handle */
uint32_t recordState; /* Service Record State */
uint16_t flags; /* Flag to keep track of marked attributes */
uint16_t handleFlag; /* Flag to keep track of service record handle */
uint16_t stateFlag; /* Flag to keep track of service record state */
} SdpRecord;
typedef struct
{
uint8_t *sdpatt_table;
uint8_t *sdpdeviceId_table;
uint16_t att_table_size;
uint16_t deviceId_size;
}sdp_AttTable_Info_t;
#endif

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,263 @@
#ifndef __SPP_API_H
#define __SPP_API_H
#include <stdbool.h>
#include "bt_types.h"
#include "rfcomm_api.h"
#include "sdp_api.h"
/*---------------------------------------------------------------------------
* Serial Port Profile (SPP) layer
*
* The Serial Port Profile (SPP) specification defines procedures
* and protocols for Bluetooth devices emulating RS232 or other serial
* connections.
*/
/****************************************************************************
*
* Section: Configuration Constants
*
* The following defines are configuration constants that allow
* an implementer to include/exclude functionality from SPP.
*
****************************************************************************/
/*---------------------------------------------------------------------------
* SPP_SERVER constant
* Configuration constant to enable code for Serial Port Profile
* server. If the device is client-only, this should be defined as
* XA_DISABLED in overide.h.
*/
#ifndef SPP_SERVER
#define SPP_SERVER XA_ENABLED
#endif
/*---------------------------------------------------------------------------
* SPP_CLIENT constant
* Configuration constant to enable code for Serial Port Profile
* client. If the device is server-only, this should be defined as
* XA_DISABLED in overide.h.
*/
#ifndef SPP_CLIENT
#define SPP_CLIENT XA_ENABLED
#endif
/****************************************************************************
*
* Types
*
****************************************************************************/
/*---------------------------------------------------------------------------
* SppEvent type
*
* The application is notified of various indications and confirmations
* through a callback function. Depending on the event, different
* elements of the SppCallbackParms "SppCallbackParms.p" union will be
* valid.
*/
typedef uint16_t SppEvent;
/** A connection has been established with a remote device.
*
* When this callback is received, the "SppCallbackParms.p.remDev" field
* contains a pointer to the remote device context.
*/
#define SPP_EVENT_REMDEV_CONNECTED 0
/** A connection has been terminated for a remote device.
*
* When this callback is received, the "SppCallbackParms.p.other" field
* contains a 0.
*/
#define SPP_EVENT_REMDEV_DISCONNECTED 1
#define SPP_EVENT_SEND_COMPLETE 2
#define SPP_EVENT_DATA_IND 3
/* End of SppEvent */
/*---------------------------------------------------------------------------
* SppPortType type
*
* Identifies the serial port as a client (outgoing) or server (incoming).
*/
typedef uint8_t SppPortType;
#define SPP_SERVER_PORT 0x01
#define SPP_CLIENT_PORT 0x02
/* End of SppPortType */
#if SPP_SERVER == XA_ENABLED
/*---------------------------------------------------------------------------
* SppService structure
*
* Servers need this data type for registering with RFCOMM. A particular
* service may have one or more ports available. For example, a device
* might provide access to 2 modems. It is providing a single service
* (modem) via 2 serial ports.
*/
typedef struct _SppService {
RfService service; /* Required for registering service w/RFCOMM */
const uint8_t *name; /* name of service */
uint16_t nameLen; /* Length of name */
uint16_t numPorts; /* Number of ports in this service */
SdpRecord *sdpRecord; /* Description of the service */
} SppService;
#endif /* SPP_SERVER == XA_ENABLED */
#if SPP_CLIENT == XA_ENABLED
/*---------------------------------------------------------------------------
* SppClient structure
* Contains all fields unique to clients. SppClient is a data type in
* device structures (SppDev) for clients.
*/
typedef struct _SppClient {
/* === Internal use only === */
BtRemoteDevice *remDev;
uint8_t serverId;
SdpQueryToken sdpToken;
} SppClient;
#endif
typedef struct _SppCallbackParms SppCallbackParms;
typedef struct _SppDev SppDev;
enum spp_type_t{
SPP_DATA_SBC,
SPP_DATA_AAC,
SPP_DATA_RAW,
SPP_CMD,
};
enum spp_cmd_type_t{
SPP_CMD_TWS_SLAVE_INF,
SPP_CMD_BUTTON_EVENT,
//SPP_CMD_AUDIO_PLAY,
//SPP_CMD_AUDIO_PAUSE,
//SPP_CMD_AUDIO_NEXT,
//SPP_CMD_AUDIO_PREV,
//SPP_CMD_VOLUME_DOWN,
//SPP_CMD_VOLUME_UP,
//SPP_CMD_VOLUME_ADJUST,
SPP_CMD_POWER_OFF,
};
/*---------------------------------------------------------------------------
* SppCallbackParms structure
*
* A pointer to this structure is sent to the application's callback function
* notifying the application of state changes or important events.
*/
struct _SppCallbackParms {
SppEvent event; /* Event associated with the callback */
BtStatus status; /* Status of the callback event */
/* For certain events, a single member of this union will be valid.
* See SppEvent documentation for more information.
*/
union {
void *other;
BtRemoteDevice *remDev;
BtPacket *pkt;
} p;
};
/*---------------------------------------------------------------------------
* SppCallback type
*
* A function of this type is called to indicate events to the application.
*/
typedef void (*SppCallback)(SppDev *locDev, SppCallbackParms *Info);
/* End of SppCallback */
typedef struct _SppModeStruct {
BtRemoteDevice *remDev;
SppCallback callback;
} SppModeStruct;
/*---------------------------------------------------------------------------
* SppDev structure
* This structure defines an SPP device. A user of SPP must allocate
* one SppDev for each serial device. Members should not be accessed
* directly.
*/
struct _SppDev {
/* Pointer to platform-specific data. This pointer is passed to all
* platform-specific functions (prefaced SPPOS_).
*/
void *osDev;
SppPortType portType; /* SPP_SERVER_PORT or SPP_CLIENT_PORT */
/* Fields specific to clients and servers */
union {
#if SPP_CLIENT == XA_ENABLED
SppClient client;
#endif
#if SPP_SERVER == XA_ENABLED
SppService *sppService;
#endif
} type;
/* === Internal use only === */
SppCallback callback; /* application callback function */
BtSecurityRecord sppSec;
/* Server / Client elements */
uint8_t state; /* device state */
RfChannel channel;
CmgrHandler cmgrHandler;
RfModemStatus rModemStatus; /* remote modem status */
RfModemStatus lModemStatus; /* local modem status */
RfLineStatus lineStatus;
RfPortSettings portSettings;
uint8_t xonChar;
uint8_t xoffChar;
int16_t highWater; /* when rRing.dataLen >= highWater,
flow off rx */
uint8_t credit; /* rx credits outstanding */
uint8_t msr; /* Modem Status Register */
int16_t breakLen;
};
/* SPP_Open has not been called or SPP_Closed was last called */
#define DEVICE_STATE_CLOSED 0
/* SPP_Open has been called but the device is not connected. */
#define DEVICE_STATE_DISCONNECTED 1
/* The device is opened and connected to a remote device. */
#define DEVICE_STATE_CONNECTED 2
//bool spp_Init(void);
BtStatus spp_send(SppDev *dev, uint8_t *data, uint16_t datalen);
BtStatus spp_connect(SppDev *dev, BD_ADDR *addr);
BtStatus spp_disconnect(SppDev *dev);
BtStatus spp_register(SppDev *dev, BtSecurityParms *sec_parm, uint8_t role, SppCallback callback);
#endif /* __SPP_API_H */