mirror of https://github.com/ARMmbed/mbed-os.git
commit
7bcc63b202
|
@ -0,0 +1,2 @@
|
|||
Unless specifically indicated otherwise in a file, files are licensed under the
|
||||
Permissive Binary License1.0 (PBL-1.0) as can be found in: LICENSE-permissive-binary-license-1.0.txt
|
|
@ -0,0 +1,49 @@
|
|||
Permissive Binary License
|
||||
|
||||
Version 1.0, September 2015
|
||||
|
||||
Redistribution. Redistribution and use in binary form, without
|
||||
modification, are permitted provided that the following conditions are
|
||||
met:
|
||||
|
||||
1) Redistributions must reproduce the above copyright notice and the
|
||||
following disclaimer in the documentation and/or other materials
|
||||
provided with the distribution.
|
||||
|
||||
2) Unless to the extent explicitly permitted by law, no reverse
|
||||
engineering, decompilation, or disassembly of this software is
|
||||
permitted.
|
||||
|
||||
3) Redistribution as part of a software development kit must include the
|
||||
accompanying file named “DEPENDENCIES” and any dependencies listed in
|
||||
that file.
|
||||
|
||||
4) Neither the name of the copyright holder nor the names of its
|
||||
contributors may be used to endorse or promote products derived from
|
||||
this software without specific prior written permission.
|
||||
|
||||
Limited patent license. The copyright holders (and contributors) grant a
|
||||
worldwide, non-exclusive, no-charge, royalty-free patent license to
|
||||
make, have made, use, offer to sell, sell, import, and otherwise
|
||||
transfer this software, where such license applies only to those patent
|
||||
claims licensable by the copyright holders (and contributors) that are
|
||||
necessarily infringed by this software. This patent license shall not
|
||||
apply to any combinations that include this software. No hardware is
|
||||
licensed hereunder.
|
||||
|
||||
If you institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the software
|
||||
itself infringes your patent(s), then your rights granted under this
|
||||
license shall terminate as of the date such litigation is filed.
|
||||
|
||||
DISCLAIMER. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
||||
CONTRIBUTORS "AS IS." ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
|
||||
NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
|
||||
TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,10 @@
|
|||
#ifndef _ODIN_W2_MBEDTLS_CONFIG_H_
|
||||
#define _ODIN_W2_MBEDTLS_CONFIG_H_
|
||||
|
||||
#define MBEDTLS_ARC4_C
|
||||
#define MBEDTLS_DES_C
|
||||
#define MBEDTLS_MD4_C
|
||||
#define MBEDTLS_MD5_C
|
||||
#define MBEDTLS_SHA1_C
|
||||
|
||||
#endif /* _ODIN_W2_MBEDTLS_CONFIG_H_ */
|
|
@ -0,0 +1,218 @@
|
|||
/* ODIN-W2 implementation of WiFiInterface
|
||||
* Copyright (c) 2016 u-blox Malmö AB
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef ODIN_WIFI_INTERFACE_H
|
||||
#define ODIN_WIFI_INTERFACE_H
|
||||
|
||||
#include "WiFiInterface.h"
|
||||
#include "Callback.h"
|
||||
#include "mbed_events.h"
|
||||
|
||||
#include "rtos.h"
|
||||
#include "emac_api.h"
|
||||
#include "nsapi_types.h"
|
||||
#include "lwip/netif.h"
|
||||
|
||||
typedef Queue<void*, 1> MsgQueue;
|
||||
|
||||
class OdinWiFiInterface;
|
||||
|
||||
struct PrivContext;
|
||||
|
||||
/** OdinWiFiInterface class
|
||||
* Implementation of the WiFiInterface for the ODIN-W2 module
|
||||
*/
|
||||
class OdinWiFiInterface : public WiFiInterface
|
||||
{
|
||||
public:
|
||||
/** OdinWiFiInterface lifetime
|
||||
*/
|
||||
OdinWiFiInterface();
|
||||
|
||||
OdinWiFiInterface(bool debug);
|
||||
|
||||
~OdinWiFiInterface();
|
||||
|
||||
/** Set the WiFi network credentials
|
||||
*
|
||||
* @param ssid Name of the network to connect to
|
||||
* @param pass Security passphrase to connect to the network
|
||||
* @param security Type of encryption for connection
|
||||
* (defaults to NSAPI_SECURITY_NONE)
|
||||
* @return 0 on success, or error code on failure
|
||||
*/
|
||||
virtual int set_credentials(const char *ssid, const char *pass, nsapi_security_t security = NSAPI_SECURITY_NONE);
|
||||
|
||||
/** Set the WiFi network channel
|
||||
*
|
||||
* @param channel Channel on which the connection is to be made, or 0 for any (Default: 0)
|
||||
* @return 0 on success, or error code on failure
|
||||
*/
|
||||
virtual int set_channel(uint8_t channel);
|
||||
|
||||
/** Start the interface
|
||||
*
|
||||
* Attempts to connect to a WiFi network.
|
||||
*
|
||||
* @param ssid Name of the network to connect to
|
||||
* @param pass Security passphrase to connect to the network
|
||||
* @param security Type of encryption for connection (Default: NSAPI_SECURITY_NONE)
|
||||
* @param channel Channel on which the connection is to be made, or 0 for any (Default: 0)
|
||||
* @return 0 on success, or error code on failure
|
||||
*/
|
||||
virtual int connect(const char *ssid,
|
||||
const char *pass,
|
||||
nsapi_security_t security = NSAPI_SECURITY_NONE,
|
||||
uint8_t channel = 0);
|
||||
|
||||
/** Start the interface
|
||||
*
|
||||
* Attempts to connect to a WiFi network. Requires ssid and passphrase to be set.
|
||||
* If passphrase is invalid, NSAPI_ERROR_AUTH_ERROR is returned.
|
||||
*
|
||||
* @return 0 on success, negative error code on failure
|
||||
*/
|
||||
virtual int connect();
|
||||
|
||||
/** Stop the interface
|
||||
*
|
||||
* @return 0 on success, or error code on failure
|
||||
*/
|
||||
virtual int disconnect();
|
||||
|
||||
/** Get the local MAC address
|
||||
*
|
||||
* Provided MAC address is intended for info or debug purposes and
|
||||
* may not be provided if the underlying network interface does not
|
||||
* provide a MAC address
|
||||
*
|
||||
* @return Null-terminated representation of the local MAC address
|
||||
* or null if no MAC address is available
|
||||
*/
|
||||
virtual const char *get_mac_address();
|
||||
|
||||
/** Get the local IP address
|
||||
*
|
||||
* @return Null-terminated representation of the local IP address
|
||||
* or null if no IP address has been recieved
|
||||
*/
|
||||
virtual const char *get_ip_address();
|
||||
|
||||
/** Get the local network mask
|
||||
*
|
||||
* @return Null-terminated representation of the local network mask
|
||||
* or null if no network mask has been recieved
|
||||
*/
|
||||
virtual const char *get_netmask();
|
||||
|
||||
/** Get the local gateway
|
||||
*
|
||||
* @return Null-terminated representation of the local gateway
|
||||
* or null if no network mask has been recieved
|
||||
*/
|
||||
virtual const char *get_gateway();
|
||||
|
||||
/** Set a static IP address
|
||||
*
|
||||
* Configures this network interface to use a static IP address.
|
||||
* Implicitly disables DHCP, which can be enabled in set_dhcp.
|
||||
* Requires that the network is disconnected.
|
||||
*
|
||||
* @param address Null-terminated representation of the local IP address
|
||||
* @param netmask Null-terminated representation of the local network mask
|
||||
* @param gateway Null-terminated representation of the local gateway
|
||||
* @return 0 on success, negative error code on failure
|
||||
*/
|
||||
virtual int set_network(const char *ip_address, const char *netmask, const char *gateway);
|
||||
|
||||
/** Enable or disable DHCP on the network
|
||||
*
|
||||
* Enables DHCP on connecting the network. Defaults to enabled unless
|
||||
* a static IP address has been assigned. Requires that the network is
|
||||
* disconnected.
|
||||
*
|
||||
* @param dhcp True to enable DHCP
|
||||
* @return 0 on success, negative error code on failure
|
||||
*/
|
||||
virtual int set_dhcp(bool dhcp);
|
||||
|
||||
/** Gets the current radio signal strength for active connection
|
||||
*
|
||||
* @return Connection strength in dBm (negative value),
|
||||
* or 0 if measurement impossible
|
||||
*/
|
||||
virtual int8_t get_rssi();
|
||||
|
||||
/** Scan for available networks
|
||||
*
|
||||
* If the network interface is set to non-blocking mode, scan will attempt to scan
|
||||
* for WiFi networks asynchronously and return NSAPI_ERROR_WOULD_BLOCK. If a callback
|
||||
* is attached, the callback will be called when the operation has completed.
|
||||
*
|
||||
* @param ap Pointer to allocated array to store discovered AP
|
||||
* @param count Size of allocated @a res array, or 0 to only count available AP
|
||||
* @param timeout Timeout in milliseconds; 0 for no timeout (Default: 0)
|
||||
* @return Number of entries in @a, or if @a count was 0 number of available networks, negative on error
|
||||
* see @a nsapi_error
|
||||
*/
|
||||
virtual int scan(WiFiAccessPoint *res, unsigned count);
|
||||
|
||||
/** Sets timeout for connection setup. Note that the time for DHCP retrieval is not included.
|
||||
*
|
||||
* @param timeout Timeout in ms. Use 0 for waiting forever. The timeout might take up to X sec longer than
|
||||
* specified since the Wi-Fi driver might need some time to finish and cleanup.
|
||||
* @return 0 on success, negative error code on failure
|
||||
*/
|
||||
virtual void set_timeout(int timeout);
|
||||
|
||||
virtual NetworkStack *get_stack();
|
||||
|
||||
protected:
|
||||
|
||||
private:
|
||||
|
||||
int connect_async(const char *ssid,
|
||||
const char *pass,
|
||||
nsapi_security_t security = NSAPI_SECURITY_NONE,
|
||||
uint8_t channel = 0,
|
||||
void *data = NULL,
|
||||
unsigned timeout = 0);
|
||||
|
||||
bool start(bool debug);
|
||||
bool stop();
|
||||
|
||||
char _mac_addr_str[18];
|
||||
// Private context to share between C and C++ calls
|
||||
PrivContext* _priv_context;
|
||||
const char *_ssid;
|
||||
const char *_pass;
|
||||
char _ip_address[IPADDR_STRLEN_MAX];
|
||||
char _netmask[IPADDR_STRLEN_MAX];
|
||||
char _gateway[IPADDR_STRLEN_MAX];
|
||||
nsapi_security_t _security;
|
||||
uint8_t _channel;
|
||||
bool _use_dhcp;
|
||||
int _timeout;
|
||||
// Event queue when the driver context need to be used
|
||||
EventQueue* _odin_event_queue;
|
||||
int32_t target_id;
|
||||
// Event queue for sending start up and connection events from driver to this class
|
||||
MsgQueue _event_queue;
|
||||
// Event queue for sending scan events from driver to this class
|
||||
MsgQueue _scan_event_queue;
|
||||
};
|
||||
|
||||
#endif
|
|
@ -0,0 +1,204 @@
|
|||
/*---------------------------------------------------------------------------
|
||||
* Copyright (c) 2016, u-blox Malmö, All Rights Reserved
|
||||
* SPDX-License-Identifier: LicenseRef-PBL
|
||||
*
|
||||
* This file and the related binary are licensed under the
|
||||
* Permissive Binary License, Version 1.0 (the "License");
|
||||
* you may not use these files except in compliance with the License.
|
||||
*
|
||||
* You may obtain a copy of the License here:
|
||||
* LICENSE-permissive-binary-license-1.0.txt and at
|
||||
* https://www.mbed.com/licenses/PBL-1.0
|
||||
*
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* Component :
|
||||
* File : bt_types.h
|
||||
*
|
||||
* Description : Common Bluetooth types
|
||||
*-------------------------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
* @file bt_types.h
|
||||
* @brief Common Bluetooth types
|
||||
*/
|
||||
|
||||
#ifndef _BT_TYPES_H_
|
||||
#define _BT_TYPES_H_
|
||||
|
||||
#include "cb_comdefs.h"
|
||||
|
||||
/*===========================================================================
|
||||
* DEFINES
|
||||
*=========================================================================*/
|
||||
|
||||
#define SIZE_OF_BD_ADDR (6)
|
||||
#define SIZE_OF_COD (3)
|
||||
#define SIZE_OF_LINK_KEY (16)
|
||||
#define SIZE_OF_NAME (248)
|
||||
#define SIZE_OF_PIN_CODE ((cb_uint8)16)
|
||||
#define SIZE_OF_LAP (3)
|
||||
#define SIZE_OF_AFH_LMP_HCI_CHANNEL_MAP (10)
|
||||
#define CHANNEL_MAP_SIZE (5)
|
||||
#define SIZE_OF_EXT_INQ_RSP (240)
|
||||
#define MIN_PASSKEY_VALUE (0)
|
||||
#define MAX_PASSKEY_VALUE (999999)
|
||||
#define INVALID_CONN_HANDLE ((TConnHandle)0xFFFF)
|
||||
#define MAX_ADV_DATA_LENGTH (31)
|
||||
#define UUID_LENGTH (16)
|
||||
|
||||
|
||||
#define PACKET_TYPE_DM1 (0x0008)
|
||||
#define PACKET_TYPE_DH1 (0x0010)
|
||||
#define PACKET_TYPE_DM3 (0x0400)
|
||||
#define PACKET_TYPE_DH3 (0x0800)
|
||||
#define PACKET_TYPE_DM5 (0x4000)
|
||||
#define PACKET_TYPE_DH5 (0x8000)
|
||||
|
||||
#define PACKET_TYPE_NO_2_DH1 (0x0002)
|
||||
#define PACKET_TYPE_NO_3_DH1 (0x0004)
|
||||
#define PACKET_TYPE_NO_2_DH3 (0x0100)
|
||||
#define PACKET_TYPE_NO_3_DH3 (0x0200)
|
||||
#define PACKET_TYPE_NO_2_DH5 (0x1000)
|
||||
#define PACKET_TYPE_NO_3_DH5 (0x2000)
|
||||
|
||||
#define PACKET_TYPE_ALL (PACKET_TYPE_DM1 | PACKET_TYPE_DH1 | PACKET_TYPE_DM3 | PACKET_TYPE_DH3 | PACKET_TYPE_DM5 | PACKET_TYPE_DH5)
|
||||
|
||||
/*===========================================================================
|
||||
* TYPES
|
||||
*=========================================================================*/
|
||||
|
||||
typedef cb_int32 int32;
|
||||
typedef cb_uint32 uint32;
|
||||
typedef cb_boolean boolean;
|
||||
typedef cb_int8 int8;
|
||||
typedef cb_uint8 uint8;
|
||||
typedef cb_int16 int16;
|
||||
typedef cb_uint16 uint16;
|
||||
|
||||
typedef cb_uint8 TErrorCode;
|
||||
typedef cb_uint8 TLinkType;
|
||||
typedef cb_uint16 TPacketType;
|
||||
typedef cb_uint16 TConnHandle;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
BT_SECURITY_MODE_1 = 1,
|
||||
BT_SECURITY_MODE_2,
|
||||
BT_SECURITY_MODE_3,
|
||||
BT_SECURITY_MODE_4
|
||||
|
||||
} TSecurityMode;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
BT_SECURITY_LEVEL_0 = 0,
|
||||
BT_SECURITY_LEVEL_1,
|
||||
BT_SECURITY_LEVEL_2,
|
||||
BT_SECURITY_LEVEL_3,
|
||||
// Used with security modes 1,2,3 where security level is not applicable
|
||||
BT_SECURITY_LEVEL_DUMMY = 5,
|
||||
|
||||
} TSecurityLevel;
|
||||
|
||||
|
||||
typedef enum
|
||||
{
|
||||
BT_MASTER_SLAVE_POLICY_ALWAYS_MASTER = 0,
|
||||
BT_MASTER_SLAVE_POLICY_OTHER_SIDE_DECIDE = 1
|
||||
|
||||
} TMasterSlavePolicy;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
BT_TYPE_CLASSIC = 0,
|
||||
BT_TYPE_LOW_ENERGY = 1
|
||||
|
||||
} TBluetoothType;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
BT_PUBLIC_ADDRESS = 0x00,
|
||||
BT_RANDOM_ADDRESS = 0x01,
|
||||
|
||||
} TAddressType;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
cb_uint8 BdAddress[SIZE_OF_BD_ADDR];
|
||||
TAddressType AddrType;
|
||||
|
||||
} TBdAddr;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
cb_uint8 Cod[SIZE_OF_COD];
|
||||
|
||||
} TCod;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
cb_uint8 LinkKey[SIZE_OF_LINK_KEY];
|
||||
|
||||
} TLinkKey;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
cb_uint8 Name[SIZE_OF_NAME];
|
||||
|
||||
} TName;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
cb_uint8 PinCode[SIZE_OF_PIN_CODE];
|
||||
|
||||
} TPinCode;
|
||||
|
||||
typedef cb_uint32 TPasskey;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
cb_uint8 Lap[SIZE_OF_LAP];
|
||||
|
||||
} TLap;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
cb_uint8 Data[SIZE_OF_EXT_INQ_RSP];
|
||||
|
||||
} TExtInqRsp;
|
||||
|
||||
typedef cb_uint8 TAfhLmpHciChannelMap[SIZE_OF_AFH_LMP_HCI_CHANNEL_MAP];
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint16 channel[CHANNEL_MAP_SIZE];
|
||||
} TChannelMap;
|
||||
|
||||
|
||||
typedef enum
|
||||
{
|
||||
BT_ADV_TYPE_ADV = 0x01,
|
||||
BT_ADV_TYPE_SCAN = 0x00,
|
||||
} TAdvDataType;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
TAdvDataType type;
|
||||
cb_uint8 length;
|
||||
cb_uint8 data[MAX_ADV_DATA_LENGTH];
|
||||
} TAdvData;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
cb_uint16 createConnectionTimeout;
|
||||
cb_uint16 connectionIntervalMin;
|
||||
cb_uint16 connectionIntervalMax;
|
||||
cb_uint16 connectionLatency;
|
||||
cb_uint16 linkLossTimeout;
|
||||
cb_uint16 scanInterval;
|
||||
cb_uint16 scanWindow;
|
||||
} TAclParamsLe;
|
||||
|
||||
#endif /* _BT_TYPES_H */
|
|
@ -0,0 +1,94 @@
|
|||
/*---------------------------------------------------------------------------
|
||||
* Copyright (c) 2016, u-blox Malmö, All Rights Reserved
|
||||
* SPDX-License-Identifier: LicenseRef-PBL
|
||||
*
|
||||
* This file and the related binary are licensed under the
|
||||
* Permissive Binary License, Version 1.0 (the "License");
|
||||
* you may not use these files except in compliance with the License.
|
||||
*
|
||||
* You may obtain a copy of the License here:
|
||||
* LICENSE-permissive-binary-license-1.0.txt and at
|
||||
* https://www.mbed.com/licenses/PBL-1.0
|
||||
*
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* Component : Assert
|
||||
* File : cb_assert.h
|
||||
*
|
||||
* Description : ASSERT macro variations.
|
||||
*-------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef _CB_ASSERT_H_
|
||||
#define _CB_ASSERT_H_
|
||||
|
||||
#include "cb_comdefs.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/*===========================================================================
|
||||
* DEFINES
|
||||
*=========================================================================*/
|
||||
|
||||
/*
|
||||
* Internal platform function declaration.
|
||||
* Shall never be called directly.
|
||||
*/
|
||||
|
||||
extern void cbOS_error(cb_int32 errorCode, const cb_char *file, cb_uint32 line);
|
||||
extern void cbOS_error2(const cb_char *file, cb_uint32 line);
|
||||
|
||||
#ifndef NASSERT
|
||||
|
||||
#ifndef __CB_FILE__
|
||||
#define __CB_FILE__ __FILE__
|
||||
#endif
|
||||
|
||||
/*
|
||||
* If the condition (C) evaluates to FALSE, the registered error handler in cbOS
|
||||
* is called with file and line info before the system is reset.
|
||||
*/
|
||||
|
||||
#define cb_ASSERT(C) do { if(!(C)){cbOS_error2(__CB_FILE__,__LINE__);} } while(0)
|
||||
|
||||
#define cb_ASSERTC(C) do { if(!(C)){cbOS_error2(__CB_FILE__ , __LINE__);} } while(0)
|
||||
|
||||
#define cb_ASSERT2(C, E) do { if(!(C)){cbOS_error(E, __CB_FILE__ , __LINE__);} } while(0)
|
||||
|
||||
/*
|
||||
* The registered error handler is called with the file and line info before a system reset.
|
||||
*/
|
||||
|
||||
#define cb_EXIT(E) do { cbOS_error(((cb_int32)(E)), __CB_FILE__, __LINE__); } while(0)
|
||||
|
||||
|
||||
#else
|
||||
|
||||
#define cb_ASSERT(C)
|
||||
|
||||
#define cb_ASSERTC(C) do { if(!(C)){cbWD_systemReset();} } while(0) // Critical assert is never removed.
|
||||
|
||||
#define cb_ASSERT2(C, E)
|
||||
|
||||
#define cb_EXIT(E) do { cbWD_systemReset(); } while(0)
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/*===========================================================================
|
||||
* TYPES
|
||||
*=========================================================================*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _cb_ASSERT_H_ */
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,826 @@
|
|||
/**
|
||||
*---------------------------------------------------------------------------
|
||||
* Copyright (c) 2016, u-blox Malmö, All Rights Reserved
|
||||
* SPDX-License-Identifier: LicenseRef-PBL
|
||||
*
|
||||
* This file and the related binary are licensed under the
|
||||
* Permissive Binary License, Version 1.0 (the "License");
|
||||
* you may not use these files except in compliance with the License.
|
||||
*
|
||||
* You may obtain a copy of the License here:
|
||||
* LICENSE-permissive-binary-license-1.0.txt and at
|
||||
* https://www.mbed.com/licenses/PBL-1.0
|
||||
*
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* Component : Bluetooth Connection Manager
|
||||
* File : cb_bt_conn_man.h
|
||||
*
|
||||
* Description : Bluetooth Connection Management
|
||||
*
|
||||
*-------------------------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
* @file cb_bt_conn_man.h
|
||||
* @brief Connection management. Functionality for setting up and tearing
|
||||
* down Bluetooth connections. Profile services are also enabled
|
||||
* using this module.
|
||||
*/
|
||||
|
||||
#ifndef _CB_BT_CONN_MAN_H_
|
||||
#define _CB_BT_CONN_MAN_H_
|
||||
|
||||
#include "cb_comdefs.h"
|
||||
#include "bt_types.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*===========================================================================
|
||||
* DEFINES
|
||||
*=========================================================================*/
|
||||
#define cbBCM_OK (0)
|
||||
#define cbBCM_ERROR (-1)
|
||||
#define cbBCM_ILLEGAL_HANDLE (-2)
|
||||
#define cbBCM_NOT_IMPLEMENTED (-3)
|
||||
#define cbBCM_ERROR_DISCONNECTING (-4)
|
||||
#define cbBCM_ERROR_ALREADY_REGISTERED (-5)
|
||||
#define cbBCM_ERROR_ALREADY_CONNECTED (-6)
|
||||
|
||||
#define cbBCM_ACL_CONNECTION_FAILED (-7)
|
||||
#define cbBCM_SERVICE_SEARCH_FAILED (-8)
|
||||
#define cbBCM_RFCOMM_CONNECTION_FAILED (-9)
|
||||
#define cbBCM_SPS_CONNECTION_FAILED (-10)
|
||||
#define cbBCM_ACL_DISCONNECTED (-11)
|
||||
|
||||
#define cbBCM_INVALID_CONNECTION_HANDLE (cb_UINT32_MAX)
|
||||
#define cbBCM_INVALID_SERVER_CHANNEL (cb_UINT8_MAX)
|
||||
#define cbBCM_SERVICE_NAME_MAX_LEN (32)
|
||||
|
||||
#define cbBCM_DEV_ID_VENDOR_ID_SRC_BLUETOOTH (0x0001)
|
||||
#define cbBCM_DEV_ID_VENDOR_ID_SRC_USB (0x0002)
|
||||
#define cbBCM_CONNECTBLUE_VENDOR_ID (0x0071)
|
||||
|
||||
/*===========================================================================
|
||||
* TYPES
|
||||
*=========================================================================*/
|
||||
typedef cb_uint32 cbBCM_Handle;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
cbBCM_INVALID_CONNECTION = 0,
|
||||
cbBCM_SPP_CONNECTION, // Serial Port Profile
|
||||
cbBCM_DUN_CONNECTION, // Dial Up Networking Profile
|
||||
cbBCM_UUID_CONNECTION, // UUID
|
||||
cbBCM_PAN_CONNECTION, // PAN
|
||||
|
||||
cbBCM_ACL_LE_CONNECTION, // GATT
|
||||
cbBCM_SPS_CONNECTION // LE connectBlue Serial Service connection
|
||||
}cbBCM_ConnectionType;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
cbBM_LINK_QUALITY_READY_OK,
|
||||
cbBM_LINK_QUALITY_READY_ERROR
|
||||
} cbBCM_LinkQualityEvt;
|
||||
|
||||
/**
|
||||
* Bluetooth Classic Acl connection parameters
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
cb_uint16 pageTimeout; /** Length of connection attempt. Default value 5000ms. */
|
||||
cb_uint16 packetType; /** Packet types allowed in the connection. By default all packets but 3MBit EDR are allowed. */
|
||||
TMasterSlavePolicy masterSlavePolicy; /** Whether master slave switch shall be allowed or not. By default master slave switch is allowed. */
|
||||
cb_uint16 clockOffset; /** Clock offset is part in inquiry response. Using this value may result in faster connection setup Default value 0. */
|
||||
cb_uint16 linkSupervisionTimeout; /** Link supervision timeout. Default value 2000ms. */
|
||||
} cbBCM_ConnectionParameters;
|
||||
|
||||
/**
|
||||
* Bluetooth Low Energy Acl connection parameters
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
cb_uint32 createConnectionTimeout; /** Length of connection attempt in ms. Default value 5000ms. */
|
||||
cb_uint16 connectionIntervalMin; /** Minimum connection interval in ms. Default value 6ms. */
|
||||
cb_uint16 connectionIntervalMax; /** Maximum connection interval in ms. Default value 8ms. */
|
||||
cb_uint16 connectionLatency; /** Slave latency. Default value 0. */
|
||||
cb_uint16 linkLossTimeout; /** Link loss timeout in ms. Default 2000ms. */
|
||||
} cbBCM_ConnectionParametersLe;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
cbBCM_PAN_ROLE_PANU = 0,
|
||||
cbBCM_PAN_ROLE_NAP,
|
||||
cbBCM_PAN_ROLE_NONE
|
||||
}cbBCM_PAN_Role;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
TBdAddr address;
|
||||
cbBCM_ConnectionType type;
|
||||
TConnHandle aclHandle;
|
||||
TBluetoothType btType;
|
||||
cb_uint8 serverChannel;
|
||||
cb_uint8 uuid[16] ;
|
||||
cb_boolean uuidValid;
|
||||
cb_char serviceName[cbBCM_SERVICE_NAME_MAX_LEN];
|
||||
} cbBCM_ConnectionInfo;
|
||||
|
||||
typedef void (*cbBCM_ConnectInd)(
|
||||
cbBCM_Handle handle,
|
||||
cbBCM_ConnectionInfo info);
|
||||
|
||||
typedef void (*cbBCM_ConnectEvt)(
|
||||
cbBCM_Handle handle,
|
||||
cbBCM_ConnectionInfo info);
|
||||
|
||||
typedef void (*cbBCM_ConnectCnf)(
|
||||
cbBCM_Handle handle,
|
||||
cbBCM_ConnectionInfo info,
|
||||
cb_int32 status);
|
||||
|
||||
typedef void (*cbBCM_DisconnectEvt)(
|
||||
cbBCM_Handle handle);
|
||||
|
||||
typedef struct
|
||||
{
|
||||
cbBCM_ConnectInd pfConnectInd;
|
||||
cbBCM_ConnectEvt pfConnectEvt;
|
||||
cbBCM_ConnectCnf pfConnectCnf;
|
||||
cbBCM_DisconnectEvt pfDisconnectEvt;
|
||||
} cbBCM_ConnectionCallback;
|
||||
|
||||
typedef void(*cbBCM_RoleDiscoveryCallback)(
|
||||
cbBCM_Handle handle,
|
||||
cb_int8 status,
|
||||
cb_int8 role);
|
||||
|
||||
typedef void (*cbBCM_RssiCallback)(
|
||||
cbBCM_Handle handle,
|
||||
cb_int32 status,
|
||||
cb_int8 rssi);
|
||||
|
||||
typedef void (*cbBCM_DataEvt)(
|
||||
cbBCM_Handle handle,
|
||||
cb_uint8 *pBuf,
|
||||
cb_uint32 nBytes);
|
||||
|
||||
typedef void (*cbBCM_WriteCnf)(
|
||||
cbBCM_Handle handle,
|
||||
cb_int32 status);
|
||||
|
||||
/**
|
||||
* Set max number of Bluetooth links.
|
||||
* Not used by application
|
||||
* @return status TRUE if command was successful
|
||||
*/
|
||||
typedef cb_int32 (*cbBCM_SetMaxLinksCmd)(cb_uint32 maxLinks);
|
||||
|
||||
/**
|
||||
* Check if Handle is free to use
|
||||
* @return TRUE if handle is free, FALSE otherwise
|
||||
*/
|
||||
typedef cb_boolean (*cbBCM_IsHandleFree)(cbBCM_Handle handle);
|
||||
/**
|
||||
* Callback to indicate that remaining buffer size needs to be obtained from
|
||||
* upper layer. The callback returns remaining buffer size and there is
|
||||
* therefore no response function.
|
||||
* Not used by application
|
||||
* @return Number of free bytes in channel data buffer
|
||||
*/
|
||||
typedef cb_uint16 (*cbBCM_RemainBufSizeInd)(void);
|
||||
|
||||
typedef struct
|
||||
{
|
||||
cbBCM_ConnectEvt pfConnectEvt;
|
||||
cbBCM_DisconnectEvt pfDisconnectEvt;
|
||||
cbBCM_DataEvt pfDataEvt;
|
||||
cbBCM_WriteCnf pfWriteCnf;
|
||||
cbBCM_SetMaxLinksCmd pfSetMaxLinks;
|
||||
cbBCM_RemainBufSizeInd pfRemainBufSizeInd;
|
||||
cbBCM_IsHandleFree pfIsHandleFree;
|
||||
} cbBCM_DataCallback;
|
||||
|
||||
typedef void (*cbBCM_ServiceSearchCompleteCallback)(cb_int32 status);
|
||||
|
||||
typedef void (*cbBCM_ServiceSearchSppCallback)(
|
||||
cb_uint8 serverChannel,
|
||||
cb_char *pServiceName);
|
||||
|
||||
typedef void (*cbBCM_ServiceSearchDunCallback)(
|
||||
cb_uint8 serverChannel,
|
||||
cb_char *pServiceName);
|
||||
|
||||
typedef void (*cbBCM_ServiceSearchDeviceIdCallback)(
|
||||
cb_uint16 didSpecVersion,
|
||||
cb_uint16 didVendorId,
|
||||
cb_uint16 didProductId,
|
||||
cb_uint16 didProductVersion,
|
||||
cb_boolean didPrimaryService,
|
||||
cb_uint16 didVendorIdSource);
|
||||
|
||||
typedef void(*cbBCM_LinkQualityCallback)(
|
||||
cbBCM_LinkQualityEvt linkQualityEvt,
|
||||
uint8 linkQuality);
|
||||
|
||||
/*===========================================================================
|
||||
* FUNCTIONS
|
||||
*=========================================================================*/
|
||||
/**
|
||||
* Initialization of connection manager. Called during stack
|
||||
* initialization. Shall not be called by application.
|
||||
*
|
||||
* @return None
|
||||
*/
|
||||
extern void cbBCM_init(void);
|
||||
|
||||
/**
|
||||
* Enable a Bluetooth Serial Port Profile (SPP)service record to
|
||||
* allow other devices to connect to this device using SPP.
|
||||
*
|
||||
* @param pServiceName The name of the service
|
||||
* @param pServerChannel Pointer to return variable. The server channel is used to identify
|
||||
* incoming connections.
|
||||
* @param pConnectionCallback Callback structure for connection management.
|
||||
* @return If the operation is successful cbBCM_OK is returned.
|
||||
*/
|
||||
extern cb_int32 cbBCM_enableServerProfileSpp(
|
||||
cb_char *pServiceName,
|
||||
cb_uint8 *pServerChannel,
|
||||
cbBCM_ConnectionCallback *pConnectionCallback);
|
||||
|
||||
/**
|
||||
* Enable a Dial Up Networking Profile (DUN)service record to
|
||||
* allow other devices to connect to this device using DUN.
|
||||
*
|
||||
* @param pServiceName The name of the service
|
||||
* @param pServerChannel Pointer to return variable. The server channel is used to identify
|
||||
* incoming connections.
|
||||
* @param pConnectionCallback Callback structure for connection management.
|
||||
* @return If the operation is successful cbBCM_OK is returned.
|
||||
*/
|
||||
extern cb_int32 cbBCM_enableServerProfileDun(
|
||||
cb_char *pServiceName,
|
||||
cb_uint8 *pServerChannel,
|
||||
cbBCM_ConnectionCallback *pConnectionCallback);
|
||||
|
||||
/**
|
||||
* Enable a service record with an application specific UUID.
|
||||
* This is used to enable Android and iOS support.
|
||||
*
|
||||
* @param pUuid128 The UUID of the service.
|
||||
* @param pServiceName The name of the service
|
||||
* @param pServerChannel Pointer to return variable. The server channel is used to identify
|
||||
* incoming connections.
|
||||
* @param pConnectionCallback Callback structure for connection management.
|
||||
* @return If the operation is successful cbBCM_OK is returned.
|
||||
*/
|
||||
extern cb_int32 cbBCM_enableServerProfileUuid128(
|
||||
cb_uint8 *pUuid128,
|
||||
cb_char *pServiceName,
|
||||
cb_uint8 *pServerChannel,
|
||||
cbBCM_ConnectionCallback *pConnectionCallback);
|
||||
|
||||
|
||||
/**
|
||||
* Registers the server role of the local device. If role is cbBCM_PAN_ROLE_NAP a service
|
||||
* record will be registred in the local service data base. The local device can only act as a
|
||||
* PAN NAP or Pan user at a time. If PAN NAP is enabled the device will only accept incoming
|
||||
* connections from PAN users. If PAN user is enabled it is only possible to be connected to
|
||||
* one remote PAN NAP device.
|
||||
*
|
||||
* @param pServiceName The name of the service
|
||||
* @param role The PAN role of the local device
|
||||
* @param pConnectionCallback Callback structure for connection management.
|
||||
* @return If the operation is successful cbBCM_OK is returned.
|
||||
*/
|
||||
extern cb_int32 cbBCM_enableServerProfilePan(
|
||||
cb_char *pServiceName,
|
||||
cbBCM_PAN_Role role,
|
||||
cbBCM_ConnectionCallback *pConnectionCallback);
|
||||
|
||||
/**
|
||||
* Enable device id service record.The device id service record is a method by which
|
||||
* Bluetooth devices may provide information that may be used by peer Bluetooth devices
|
||||
* to find representative icons or load associated support software.
|
||||
* This information is published as Bluetooth SDP records, and optionally in the
|
||||
* Extended Inquiry Response.
|
||||
* @param vendorId Uniquely identifier for the vendor of the device. Used in conjunction with required attribute 0x0205, VendorIDSource, which determines which organization assigned the VendorID value. Note: The Bluetooth Special Interest Group assigns Device ID Vendor ID and the USB Implementer's Forum assigns vendor IDs, either of which can be used for the VendorID value here. Device providers should procure the vendor ID from the USB Implementer's Forum or the Company Identifier from the Bluetooth SIG. The VendorID '0xFFFF' is reserved as the default VendorID when no Device ID Service Record is present in the device.
|
||||
* @param productId This is intended to distinguish between different products made by the vendor above. These IDs are managed by the vendors themselves.
|
||||
* @param version A numeric expression identifying the device release number in Binary-Coded Decimal. This is a vendor-assigned field, which defines the version of the product identified by the VendorID and ProductID attributes. This attribute is intended to differentiate between versions of products with identical VendorIDs and ProductIDs. The value of the field is 0xJJMN for version JJ.M.N (JJ - major version number, M - minor version number, N - sub-minor version number); e.g., version 2.1.3 is represented with value 0x0213 and version 2.0.0 is represented with a value of 0x0200. When upward-compatible changes are made to the device, it is recommended that the minor version number be incremented. If incompatible changes are made to the device, it is recommended that the major version number be incremented.
|
||||
* @param vendorIdSource Organization that assigned the VendorID attribute. Use 0x0001 for Bluetooth SIG assigned Device ID Vendor ID value from the Assigned Numbers document and 0x0002 for USB Implementer's Forum assigned Vendor ID value
|
||||
* @return If the operation is successful cbBCM_OK is returned. Note that only one device id service record can be registered.
|
||||
*/
|
||||
extern cb_int32 cbBCM_enableDeviceIdServiceRecord(
|
||||
cb_uint16 vendorId,
|
||||
cb_uint16 productId,
|
||||
cb_uint16 version,
|
||||
cb_uint16 vendorIdSource);
|
||||
|
||||
/**
|
||||
* Set Bluetooth watchdog settings
|
||||
*
|
||||
* @param disconnectReset Reset the device on any dropped Bluetooth connection
|
||||
* @return void
|
||||
*/
|
||||
extern void cbBCM_setBluetoothWatchdogValue(cb_uint32 disconnectReset);
|
||||
|
||||
/**
|
||||
* Set the packet types to use. Call cbBCM_cmdChangePacketType()
|
||||
* to start using the new packet types.
|
||||
*
|
||||
* @param packetType See packet types in bt_types.h
|
||||
* @return If the operation is successful cbBCM_OK is returned.
|
||||
*/
|
||||
extern cb_uint32 cbBCM_setPacketType(cb_uint16 packetType);
|
||||
|
||||
/**
|
||||
* Get BT classic packet type.
|
||||
*
|
||||
* @return Allowed packet types returned.
|
||||
*/
|
||||
extern cb_uint16 cbBCM_getPacketType(void);
|
||||
|
||||
/**
|
||||
* Set max number of Bluetooth classic links. Reconfigures buffer management.
|
||||
*
|
||||
* @param maxLinks Max number of Bluetooth classic connections.
|
||||
* @return If the operation is successful cbBCM_OK is returned.
|
||||
*/
|
||||
extern cb_int32 cbBCM_setMaxLinksClassic(cb_uint16 maxLinks);
|
||||
|
||||
/**
|
||||
* Get max number of Bluetooth classic links.
|
||||
*
|
||||
* @return The maximum number of Bluetooth classic links.
|
||||
*/
|
||||
extern cb_uint16 cbBCM_getMaxLinksClassic(void);
|
||||
|
||||
/**
|
||||
* Set max number of Bluetooth Low Energy links. Reconfigures buffer management.
|
||||
*
|
||||
* @param maxLinks Max number of Bluetooth Low Energy connections.
|
||||
* @return If the operation is successful cbBCM_OK is returned.
|
||||
*/
|
||||
extern cb_int32 cbBCM_setMaxLinksLE(cb_uint16 maxLinks);
|
||||
|
||||
/**
|
||||
* Get max number of Bluetooth Low Energy links.
|
||||
*
|
||||
* @return The maximum number of Bluetooth Low Energy links.
|
||||
*/
|
||||
extern cb_uint16 cbBCM_getMaxLinksLE(void);
|
||||
|
||||
/**
|
||||
* Initiate a Bluetooth Serial Port Profile connection.
|
||||
* The connection sequence includes ACL connection setup, SDP service
|
||||
* search and RFCOMM connection setup. The server channel of the first
|
||||
* valid SPP service record will be used. A pfConnectCnf callback will
|
||||
* be received when the connection is complete.The error code in the
|
||||
* callback is cbBCM_OK if the connection was successfully established.
|
||||
* The error code in the callback is cbBCM_ERROR if the connection failed.
|
||||
* @param pAddress Pointer to address of remote device.
|
||||
* @param pServiceName Name of SPP service. Automatic service search
|
||||
* is performed to find a service with matching name.
|
||||
* If set to NULL then the last of the SPP services
|
||||
* on the remote device will be used. If serverChannel
|
||||
* parameter is different than cbBCM_INVALID_SERVER_CHANNEL
|
||||
* this parameter is ignored and the specified server channel
|
||||
* will be used.
|
||||
* @param serverChannel RFCOMM server channel that shall be used. Set to
|
||||
* cbBCM_INVALID_SERVER_CHANNEL to perform automatic
|
||||
* service search to find the server channel.
|
||||
* @param pAclParameters Link configuration including link supervision timeout
|
||||
* and master slave policy. Pass NULL to use default connection
|
||||
* parameters.
|
||||
* @param pConnectionCallback Callback structure for connection management.
|
||||
* @return If the operation is successful the connection handle is returned. If
|
||||
* not cbBCM_INVALID_CONNECTION_HANDLE is returned.
|
||||
*/
|
||||
extern cbBCM_Handle cbBCM_reqConnectSpp(
|
||||
TBdAddr *pAddress,
|
||||
cb_char *pServiceName,
|
||||
cb_uint8 serverChannel,
|
||||
cbBCM_ConnectionParameters *pAclParameters,
|
||||
cbBCM_ConnectionCallback *pConnectionCallback);
|
||||
|
||||
/**
|
||||
* Accept or reject an incoming SPP connection. This is a
|
||||
* response to a cbBCM_ConnectInd connection indication.
|
||||
*
|
||||
* @param handle Connection handle
|
||||
* @param accept TRUE to accept the incoming connection.
|
||||
FALSE to reject.
|
||||
* @return If the operation is successful cbBCM_OK is returned.
|
||||
*/
|
||||
extern cb_int32 cbBCM_rspConnectSppCnf(
|
||||
cbBCM_Handle handle,
|
||||
cb_boolean accept);
|
||||
|
||||
/**
|
||||
* Initiate a Bluetooth Dial Up Networking Profile connection.
|
||||
* The connection sequence includes ACL connection setup, SDP service
|
||||
* search and RFCOMM connection setup. The server channel of the first
|
||||
* valid SPP service record will be used. A pfConnectCnf callback will
|
||||
* be received when the connection is complete.The error code in the
|
||||
* callback is cbBCM_OK if the connection was successfully established.
|
||||
* The error code in the callback is cbBCM_ERROR if the connection failed.
|
||||
* @param pAddress Pointer to address of remote device.
|
||||
* @param pServiceName Name of DUN service. Automatic service search
|
||||
* is performed to find a service with matching name.
|
||||
* If set to NULL then the last of the DUN services
|
||||
* on the remote device will be used. If serverChannel
|
||||
* parameter is different than cbBCM_INVALID_SERVER_CHANNEL
|
||||
* this parameter is ignored and the specified server channel
|
||||
* will be used.
|
||||
* @param serverChannel RFCOMM server channel that shall be used. Set to
|
||||
* cbBCM_INVALID_SERVER_CHANNEL to perform automatic
|
||||
* service search to find the server channel.
|
||||
* @param pAclParameters Link configuration including link supervision timeout
|
||||
* and master slave policy. Pass NULL to use default connection
|
||||
* parameters.
|
||||
* @param pConnectionCallback Callback structure for connection management.
|
||||
* @return If the operation is successful the connection handle is returned. If
|
||||
* not cbBCM_INVALID_CONNECTION_HANDLE is returned.
|
||||
*/
|
||||
extern cbBCM_Handle cbBCM_reqConnectDun(
|
||||
TBdAddr *pAddress,
|
||||
cb_char *pServiceName,
|
||||
cb_uint8 serverChannel,
|
||||
cbBCM_ConnectionParameters *pAclParameters,
|
||||
cbBCM_ConnectionCallback *pConnectionCallback);
|
||||
|
||||
/**
|
||||
* Accept or reject an incoming DUN connection. This is a
|
||||
* response to a cbBCM_ConnectInd connection indication.
|
||||
*
|
||||
* @param handle Connection handle
|
||||
* @param accept TRUE to accept the incoming connection.
|
||||
FALSE to reject.
|
||||
* @return If the operation is successful cbBCM_OK is returned.
|
||||
*/
|
||||
extern cb_int32 cbBCM_rspConnectDunCnf(
|
||||
cbBCM_Handle handle,
|
||||
cb_boolean accept);
|
||||
|
||||
/**
|
||||
* Initiate a Bluetooth Serial Port Profile connection with a specific UUID.
|
||||
* The connection sequence includes ACL connection setup, SDP service
|
||||
* search and RFCOMM connection setup. The server channel of the first
|
||||
* valid SPP service record with the specified UUID will be used. A pfConnectCnf
|
||||
* callback will be received when the connection is complete.The error code in the
|
||||
* callback is cbBCM_OK if the connection was successfully established.
|
||||
* The error code in the callback is cbBCM_ERROR if the connection failed.
|
||||
* @param pAddress Pointer to address of remote device.
|
||||
* @param pUuid Pointer to uuid of the remote service.
|
||||
* @param pServiceName Name of SPP service. Automatic service search
|
||||
* is performed to find a service with matching name.
|
||||
* If set to NULL then the last of the SPP services
|
||||
* on the remote device will be used. If serverChannel
|
||||
* parameter is different than cbBCM_INVALID_SERVER_CHANNEL
|
||||
* this parameter is ignored and the specified server channel
|
||||
* will be used.
|
||||
* @param serverChannel RFCOMM server channel that shall be used. Set to
|
||||
* cbBCM_INVALID_SERVER_CHANNEL to perform automatic
|
||||
* service search to find the server channel.
|
||||
* @param pAclParameters Link configuration including link supervision timeout
|
||||
* and master slave policy. Pass NULL to use default connection
|
||||
* parameters.
|
||||
* @param pConnectionCallback Callback structure for connection management.
|
||||
* @return If the operation is successful the connection handle is returned. If
|
||||
* not cbBCM_INVALID_CONNECTION_HANDLE is returned.
|
||||
*/
|
||||
extern cbBCM_Handle cbBCM_reqConnectUuid(
|
||||
TBdAddr *pAddress,
|
||||
cb_uint8 *pUuid,
|
||||
cb_char *pServiceName,
|
||||
cb_uint8 serverChannel,
|
||||
cbBCM_ConnectionParameters *pAclParameters,
|
||||
cbBCM_ConnectionCallback *pConnectionCallback);
|
||||
|
||||
/**
|
||||
* Accept or reject an incoming SPP connection. This is a
|
||||
* response to a cbBCM_ConnectInd connection indication.
|
||||
*
|
||||
* @param handle Connection handle
|
||||
* @param accept TRUE to accept the incoming connection.
|
||||
FALSE to reject.
|
||||
* @return If the operation is successful cbBCM_OK is returned.
|
||||
*/
|
||||
extern cb_int32 cbBCM_rspConnectUuidCnf(
|
||||
cbBCM_Handle handle,
|
||||
cb_boolean accept);
|
||||
|
||||
/**
|
||||
* Initiate a Bluetooth PAN Profile connection.
|
||||
* The connection sequence includes ACL connection setup and L2CAP connection setup.
|
||||
* A pfConnectCnf callback will be received when the connection is complete.
|
||||
* The error code in the*callback is cbBCM_OK if the connection was successfully established.
|
||||
* The error code in the callback is cbBCM_ERROR if the connection failed.
|
||||
*
|
||||
* @param pAddress Pointer to address of remote device.
|
||||
* @param remoteRole PAN role of the remote device
|
||||
* @param localRole PAN role of the local device
|
||||
* @param pAclParams Link configuration including link supervision timeout
|
||||
* and master slave policy. Pass NULL to use default connection
|
||||
* parameters.
|
||||
* @param pConnectionCallback Callback structure for connection management.
|
||||
* @return If the operation is successful the connection handle is returned. If
|
||||
* not cbBCM_INVALID_CONNECTION_HANDLE is returned.
|
||||
*/
|
||||
extern cbBCM_Handle cbBCM_reqConnectPan(
|
||||
TBdAddr *pAddress,
|
||||
cbBCM_PAN_Role remoteRole,
|
||||
cbBCM_PAN_Role localRole,
|
||||
cbBCM_ConnectionParameters *pAclParams,
|
||||
cbBCM_ConnectionCallback *pConnectionCallback);
|
||||
|
||||
/**
|
||||
* Accept or reject an incoming PAN connection. This is a
|
||||
* response to a cbBCM_ConnectInd connection indication.
|
||||
*
|
||||
* @param handle Connection handle
|
||||
* @param accept TRUE to accept the incoming connection.
|
||||
* FALSE to reject.
|
||||
* @return If the operation is successful cbBCM_OK is returned.
|
||||
*/
|
||||
extern cb_int32 cbBCM_rspConnectPan(
|
||||
cbBCM_Handle handle,
|
||||
cb_boolean accept);
|
||||
|
||||
/**
|
||||
* Enable Serial Port Service.
|
||||
* When the device is acting Bluetooth Low Energy peripheral the Serial
|
||||
* Port Service will be added to the attribute table.
|
||||
*
|
||||
* @param pConnectionCallback Callback structure for connection management.
|
||||
* @return If the operation is successful cbBCM_OK is returned.
|
||||
* @param pConnectionCallback Callback structure for connection management.
|
||||
* @return If the operation is successful cbBCM_OK is returned.
|
||||
*/
|
||||
extern cb_int32 cbBCM_enableSps(
|
||||
cbBCM_ConnectionCallback *pConnectionCallback);
|
||||
|
||||
/**
|
||||
* Enable or disable Bluetooth low energy auto connect.
|
||||
* When the device is acting as central and auto connect is enabled it runs
|
||||
* passive scan and initiates an ACL connection to devices that performs
|
||||
* directed advertisements.
|
||||
* The serial port service muast be enabled using cbBCM_enableSps() before
|
||||
* auto connect is enabled.
|
||||
* If SPS is enabled the SPS Gatt client will initiate a SPS connection
|
||||
* attempt on the ACL connection.
|
||||
* When the device is acting peripheral this functionality is inactive.
|
||||
*
|
||||
* @param enable Set to TRUE to enable. Set to false to disable.
|
||||
* @return If the operation is successful cbBCM_OK is returned.
|
||||
*/
|
||||
extern cb_int32 cbBCM_autoConnect(
|
||||
cb_boolean enable);
|
||||
|
||||
/**
|
||||
* Initiate a Serial Port Service connection.
|
||||
* The connection sequence includes ACL connection setup , GATT service
|
||||
* search and Serial Port Service connection setup. A connect confirm
|
||||
* callback will be received when the connection is complete. The error
|
||||
* code in the callback is cbBCM_OK if the connection was successfully established.
|
||||
* The error code in the callback is cbBCM_ERROR if the connection failed.
|
||||
* The serial port service must be enabled using cbBCM_enableSps() before
|
||||
* auto connect request is made..
|
||||
* @param pAddress Address of remote device.
|
||||
* @param pAclLeParams Link configuration parameters
|
||||
* @param pConnectionCallback Callback structure for connection management.
|
||||
* @return If the operation is successful the connection handle is returned. If
|
||||
* not cbBCM_INVALID_CONNECTION_HANDLE is returned.
|
||||
*/
|
||||
extern cbBCM_Handle cbBCM_reqConnectSps(
|
||||
TBdAddr *pAddress,
|
||||
cbBCM_ConnectionParametersLe *pAclLeParams,
|
||||
cbBCM_ConnectionCallback *pConnectionCallback);
|
||||
|
||||
/**
|
||||
* Accept or reject an incoming SPS connection. This is a
|
||||
* response to a cbBCM_ConnectInd connection indication.
|
||||
* @param handle Connection handle
|
||||
* @param accept TRUE to accept the incoming connection.
|
||||
* FALSE to reject.
|
||||
* @return If the operation is successful cbBCM_OK is returned.
|
||||
*/
|
||||
extern cb_int32 cbBCM_rspConnectSpsCnf(
|
||||
cbBCM_Handle handle,
|
||||
cb_boolean accept);
|
||||
|
||||
/**
|
||||
* Initiate a Bluetooth low energy ACL connection. The ACL connection is
|
||||
* intended for GATT communication.
|
||||
* A connect confirm callback will be received when the connection is complete. The error
|
||||
* code in the callback is cbBCM_OK if the connection was successfully established.
|
||||
* The error code in the callback is cbBCM_ERROR if the connection failed.
|
||||
* @param pAddress Address of remote device.
|
||||
* @param pAclLeParams Link configuration parameters
|
||||
* @param pConnectionCallback Callback structure for connection management.
|
||||
* @return If the operation is successful the connection handle is returned. If
|
||||
* not cbBCM_INVALID_CONNECTION_HANDLE is returned.
|
||||
*/
|
||||
extern cbBCM_Handle cbBCM_reqConnectAclLe(
|
||||
TBdAddr *pAddress,
|
||||
cbBCM_ConnectionParametersLe *pAclLeParams,
|
||||
cbBCM_ConnectionCallback *pConnectionCallback);
|
||||
|
||||
/**
|
||||
* @brief Initiate disconnection of active connection. A disconnect event
|
||||
* will be received when the disconnection is complete.
|
||||
*
|
||||
* @param handle Connection handle
|
||||
* @return If the operation is successful cbBCM_OK is returned.
|
||||
*/
|
||||
extern cb_int32 cbBCM_cmdDisconnect(
|
||||
cbBCM_Handle handle);
|
||||
|
||||
/**
|
||||
* @brief Initiate a Serial Port Profile (SPP) service search to find server channel and service name.
|
||||
* @param pAddress Address of device on which service search shall be performed.
|
||||
* @param maxServices Max number of services
|
||||
* @param pCallback Callback used to notify each found service record
|
||||
* @param pCompleteCallback Callback used to notify that the search is completed
|
||||
* @return If the operation is successful initiated cbBCM_OK is returned.
|
||||
*/
|
||||
extern cb_int32 cbBCM_reqServiceSearchSpp(
|
||||
TBdAddr *pAddress,
|
||||
cb_uint16 maxServices,
|
||||
cbBCM_ServiceSearchSppCallback pCallback,
|
||||
cbBCM_ServiceSearchCompleteCallback pCompleteCallback);
|
||||
|
||||
/**
|
||||
* @brief Initiate a Dial Up Networking (DUN) service search to find server channel and service name.
|
||||
* @param pAddress Address of device on which service search shall be performed.
|
||||
* @param maxServices Max number of services
|
||||
* @param pCallback Callback used to notify each found service record
|
||||
* @param pCompleteCallback Callback used to notify that the search is completed
|
||||
* @return If the operation is successful initiated cbBCM_OK is returned.
|
||||
*/
|
||||
extern cb_int32 cbBCM_reqServiceSearchDun(
|
||||
TBdAddr *pAddress,
|
||||
cb_uint16 maxServices,
|
||||
cbBCM_ServiceSearchSppCallback pCallback,
|
||||
cbBCM_ServiceSearchCompleteCallback pCompleteCallback);
|
||||
|
||||
/**
|
||||
* @brief Initiate a UUID service search to find server channel and service name.
|
||||
* @param pAddress Address of device on which service search shall be performed.
|
||||
* @param pUuid128 128 UUID to search for.
|
||||
* @param maxServices Max number of services
|
||||
* @param pCallback Callback used to notify each found service record
|
||||
* @param pCompleteCallback Callback used to notify that the search is completed
|
||||
* @return If the operation is successful initiated cbBCM_OK is returned.
|
||||
*/
|
||||
extern cb_int32 cbBCM_reqServiceSearchUuid(
|
||||
TBdAddr *pAddress,
|
||||
const cb_uint8 *pUuid128,
|
||||
cb_uint16 maxServices,
|
||||
cbBCM_ServiceSearchSppCallback pCallback,
|
||||
cbBCM_ServiceSearchCompleteCallback pCompleteCallback);
|
||||
|
||||
/**
|
||||
* @brief Initiate a Device information service search.
|
||||
* @param pAddress Address of device on which service search shall be performed.
|
||||
* @param maxServices Max number of services
|
||||
* @param pCallback Callback used to notify each found service record
|
||||
* @param pCompleteCallback Callback used to notify that the search is completed
|
||||
* @return If the operation is successful initiated cbBCM_OK is returned.
|
||||
*/
|
||||
cb_int32 cbBCM_reqServiceSearchDeviceId(
|
||||
TBdAddr *pAddress,
|
||||
cb_uint16 maxServices,
|
||||
cbBCM_ServiceSearchDeviceIdCallback pCallback,
|
||||
cbBCM_ServiceSearchCompleteCallback pCompleteCallback);
|
||||
|
||||
/**
|
||||
* @brief Get local Master/Slave role in an active connection.
|
||||
* @param bdAddr address to the connection
|
||||
* @param roleDiscoveryCallback Callback function used to notify the role
|
||||
* @return If the operation is successful cbBCM_OK is returned.
|
||||
*/
|
||||
extern cb_int32 cbBCM_RoleDiscovery(
|
||||
TBdAddr bdAddr,
|
||||
cbBCM_RoleDiscoveryCallback roleDiscoveryCallback);
|
||||
|
||||
/**
|
||||
* @brief Get current Received Signal Strength Indication (RSSI)
|
||||
* of an active connection.
|
||||
* @param bdAddress bt address to the connected device
|
||||
* @param rssiCallback Callback function used to notify the rssi value
|
||||
* @return If the operation is successful cbBCM_OK is returned.
|
||||
*/
|
||||
extern cb_int32 cbBCM_getRssi(
|
||||
TBdAddr bdAddress,
|
||||
cbBCM_RssiCallback rssiCallback);
|
||||
|
||||
/*
|
||||
* Read the LinkQuality .
|
||||
* @return status as int32.
|
||||
* @cbBM_LinkQualityCallback is used to provide result.
|
||||
*/
|
||||
extern cb_int32 cbBCM_GetLinkQuality(TBdAddr bdAddr, cbBCM_LinkQualityCallback linkQualityCallback);
|
||||
|
||||
/**
|
||||
* @brief Change the packet types currently used for an active Bluetooth
|
||||
* Classic connection.
|
||||
* @param handle Connection handle
|
||||
* @return If the operation is successful cbBCM_OK is returned.
|
||||
*/
|
||||
extern cb_int32 cbBCM_cmdChangePacketType(
|
||||
cbBCM_Handle handle);
|
||||
|
||||
/**
|
||||
* @brief Get the current connection parameters for an active Bluetooth
|
||||
* Low Energy ACL connection.
|
||||
* @param handle Connection handle
|
||||
* @param pConnectionInterval Connection interval
|
||||
* @param pConnectionLatency Connection latency
|
||||
* @param pLinkSupervisionTmo Link supervision timeout
|
||||
* @return If the update is successfully initiated cbBCM_OK is returned.
|
||||
*/
|
||||
extern cb_int32 cbBCM_getConnectionParams(
|
||||
cbBCM_Handle handle,
|
||||
cb_uint16 *pConnectionInterval,
|
||||
cb_uint16 *pConnectionLatency,
|
||||
cb_uint16 *pLinkSupervisionTmo);
|
||||
|
||||
/**
|
||||
* @brief Update connection parameters for an active Bluetooth
|
||||
* Low Energy ACL connection.
|
||||
* @param handle Connection handle
|
||||
* @param pAclLeParams New Link configuration parameters
|
||||
* @return If the update is successfully initiated cbBCM_OK is returned.
|
||||
*/
|
||||
extern cb_int32 cbBCM_updateConnectionParams(
|
||||
cbBCM_Handle handle,
|
||||
cbBCM_ConnectionParametersLe *pAclLeParams);
|
||||
|
||||
/**
|
||||
* Register a GATT device information service. The device information service
|
||||
* is used by remote devices to get for example the model and firmware version
|
||||
* of this device.
|
||||
* Note that an application easily can define and register its own device information
|
||||
* service if other characteristics are required.
|
||||
* @param pManufacturer String defining the manufacturer.
|
||||
* @param pModel String defining the device model.
|
||||
* @param pFwVersion String defining the firmware version.
|
||||
* @param startIndex Start index of the attribute database for the device info service.
|
||||
* Note that this must not change during the lifetime of the product.
|
||||
* @return If the operation is successful cbBCM_OK is returned.
|
||||
*/
|
||||
extern cb_int32 cbBCM_enableDevInfoService(
|
||||
const cb_char *pManufacturer,
|
||||
const cb_char *pModel,
|
||||
const cb_char *pFwVersion,
|
||||
cb_uint16 startIndex);
|
||||
|
||||
/**
|
||||
* @brief Get the address of the remote device on an
|
||||
* active connection
|
||||
*
|
||||
* @param handle Connection handle
|
||||
* @return Address of the remote device.
|
||||
*/
|
||||
extern TBdAddr cbBCM_getAddress(cbBCM_Handle handle);
|
||||
|
||||
/**
|
||||
* @brief Register a data manager for a type of connections. Shall not be
|
||||
* used by the application. Only used by data managers.
|
||||
*
|
||||
* @param type Connection type.
|
||||
* @param pDataCallback Data callback
|
||||
* @return If the operation is successful cbBCM_OK is returned.
|
||||
*/
|
||||
extern cb_int32 cbBCM_registerDataCallback(
|
||||
cbBCM_ConnectionType type,
|
||||
cbBCM_DataCallback *pDataCallback);
|
||||
|
||||
/**
|
||||
* @brief Get the protocol handle for an active connection. Shall not be used
|
||||
* by the application. Only used by data managers.
|
||||
*
|
||||
* @param handle Connection handle
|
||||
* @return If the operation is not successful cbBCM_INVALID_CONNECTION_HANDLE
|
||||
* is returned. If the operation is successful the protocol handle is
|
||||
* returned.
|
||||
*/
|
||||
extern cbBCM_Handle cbBCM_getProtocolHandle(
|
||||
cbBCM_Handle handle);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _CB_BT_CONN_MAN_H_ */
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,625 @@
|
|||
/*
|
||||
*---------------------------------------------------------------------------
|
||||
* Copyright (c) 2016, u-blox Malmö, All Rights Reserved
|
||||
* SPDX-License-Identifier: LicenseRef-PBL
|
||||
*
|
||||
* This file and the related binary are licensed under the
|
||||
* Permissive Binary License, Version 1.0 (the "License");
|
||||
* you may not use these files except in compliance with the License.
|
||||
*
|
||||
* You may obtain a copy of the License here:
|
||||
* LICENSE-permissive-binary-license-1.0.txt and at
|
||||
* https://www.mbed.com/licenses/PBL-1.0
|
||||
*
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* Component : Bluetooth Manager
|
||||
* File : cb_bt_man.h
|
||||
*
|
||||
* Description : General Bluetooth functionality
|
||||
*
|
||||
*-------------------------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
* @file cb_bt_man.h
|
||||
*
|
||||
* @brief General Bluetooth functionality. This includes initialization of
|
||||
* the Bluetooth radio and stack, handling properties such as device
|
||||
* name, scanning for other devices using inquiry or Bluetooth Low Energy
|
||||
* scan and more.
|
||||
*/
|
||||
|
||||
#ifndef _CB_BT_MAN_H_
|
||||
#define _CB_BT_MAN_H_
|
||||
|
||||
#include "cb_comdefs.h"
|
||||
#include "bt_types.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*===========================================================================
|
||||
* DEFINES
|
||||
*=========================================================================*/
|
||||
#define cbBM_OK (0)
|
||||
#define cbBM_ERROR (-1)
|
||||
#define cbBM_MAX_OUTPUT_POWER (127)
|
||||
|
||||
#define cbBM_ADV_CHANNEL_MAP_CH_37_BIT 0x01
|
||||
#define cbBM_ADV_CHANNEL_MAP_CH_38_BIT 0x02
|
||||
#define cbBM_ADV_CHANNEL_MAP_CH_39_BIT 0x04
|
||||
#define cbBM_ADV_CHANNEL_MAP_ALL (cbBM_ADV_CHANNEL_MAP_CH_37_BIT | cbBM_ADV_CHANNEL_MAP_CH_38_BIT | cbBM_ADV_CHANNEL_MAP_CH_39_BIT)
|
||||
/*===========================================================================
|
||||
* TYPES
|
||||
*=========================================================================*/
|
||||
|
||||
extern const TBdAddr invalidBdAddress;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
cbBM_INQUIRY_GENERAL = 0,
|
||||
cbBM_INQUIRY_LIMITED = 1,
|
||||
} cbBM_InquiryType;
|
||||
|
||||
typedef void (*cbBM_InquiryEventCallback)(
|
||||
TBdAddr *pBdAddress,
|
||||
TCod cod,
|
||||
cb_uint16 clockOffset,
|
||||
cb_int8 rssi,
|
||||
cb_char *pName,
|
||||
TExtInqRsp* pExtInqRsp,
|
||||
cb_uint8 length);
|
||||
|
||||
typedef void (*cbBM_InquiryCompleteCallback)(
|
||||
cb_int32 status);
|
||||
|
||||
typedef void (*cbBM_RemoteNameCallback)(
|
||||
TBdAddr *pBdAddress,
|
||||
TName *pName,
|
||||
cb_int32 status);
|
||||
|
||||
typedef enum
|
||||
{
|
||||
cbBM_DEVICE_DISCOVERY_LE_ALL = 0,
|
||||
cbBM_DEVICE_DISCOVERY_LE_GENERAL,
|
||||
cbBM_DEVICE_DISCOVERY_LE_LIMITED,
|
||||
cbBM_DEVICE_DISCOVERY_LE_ALL_NO_FILTERING
|
||||
} cbBM_DeviceDiscoveryTypeLe;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
cbBM_ACTIVE_SCAN = 0,
|
||||
cbBM_PASSIVE_SCAN = 1
|
||||
} cbBM_ScanTypeLe;
|
||||
|
||||
|
||||
typedef void (*cbBM_DeviceDiscoveryLeEventCallback)(
|
||||
TBdAddr *pBdAddress,
|
||||
cb_int8 rssi,
|
||||
cb_char *pName,
|
||||
TAdvData *pAdvData);
|
||||
|
||||
typedef void (*cbBM_DeviceDiscoveryLeCompleteCallback)(
|
||||
cb_int32 status);
|
||||
|
||||
typedef enum
|
||||
{
|
||||
cbBM_DISCOVERABLE_MODE_NONE = 0,
|
||||
cbBM_DISCOVERABLE_MODE_LIMITED = 1,
|
||||
cbBM_DISCOVERABLE_MODE_GENERAL = 2,
|
||||
} cbBM_DiscoverableMode;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
cbBM_CONNECTABLE_MODE_NOT_CONNECTABLE = 0,
|
||||
cbBM_CONNECTABLE_MODE_CONNECTABLE
|
||||
} cbBM_ConnectableMode;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
cbBM_DISCOVERABLE_MODE_LE_NONE = 0,
|
||||
cbBM_DISCOVERABLE_MODE_LE_LIMITED = 1,
|
||||
cbBM_DISCOVERABLE_MODE_LE_GENERAL = 2,
|
||||
} cbBM_DiscoverableModeLe;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
cbBM_CONNECTABLE_MODE_LE_NOT_CONNECTABLE = 0,
|
||||
cbBM_CONNECTABLE_MODE_LE_CONNECTABLE
|
||||
} cbBM_ConnectableModeLe;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
cbBM_SET_CHANNEL_MAP_CNF_POS,
|
||||
cbBM_SET_CHANNEL_MAP_CNF_NEG,
|
||||
} cbBM_ChannelMapEvt;
|
||||
|
||||
typedef void (*cbBM_ChannelMapCallb)(
|
||||
cbBM_ChannelMapEvt chMapEvt,
|
||||
TChannelMap *pChMap);
|
||||
|
||||
typedef void (*cbBM_InitComplete)(void);
|
||||
|
||||
typedef enum
|
||||
{
|
||||
cbBM_LE_ROLE_DISABLED = 0,
|
||||
cbBM_LE_ROLE_CENTRAL = 1,
|
||||
cbBM_LE_ROLE_PERIPHERAL = 2,
|
||||
} cbBM_LeRole;
|
||||
|
||||
/**
|
||||
* Bluetooth Manager initialization parameters.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
TBdAddr address; /** Bluetooth address that shall be assigned to controller. Pass invalidBdAddress to use controller default address*/
|
||||
cbBM_LeRole leRole; /** Bluetooth low energy role */
|
||||
cb_int8 maxOutputPower; /** Maximum output power. */
|
||||
cb_uint32 nvdsStartIdLinkKeysClassic; /** Start id for CLASSIC link keys storage in NVDS. */
|
||||
cb_uint32 maxLinkKeysClassic; /** Max number of CLASSIC link keys */
|
||||
cb_uint32 nvdsStartIdLinkKeysLe; /** Start id for BLE link keys storage in NVDS. */
|
||||
cb_uint32 maxLinkKeysLe; /** Max number of link keys BLE*/
|
||||
} cbBM_InitParams;
|
||||
|
||||
/*===========================================================================
|
||||
* FUNCTIONS
|
||||
*=========================================================================*/
|
||||
|
||||
/**
|
||||
* Initialize the Bluetooth Radio, the connectBlue Embedded Bluetooth
|
||||
* Stack and the Bluetooth Manager.
|
||||
* The init complete callback is used to notify when the initialization is
|
||||
* complete. During initialization default values are set for all properties.
|
||||
* The application shall set desired values for the main Bluetooth properties
|
||||
* such as local name after the initialization is complete. After init the device
|
||||
* is non discoverable and non connectable.
|
||||
*
|
||||
* @param pInitParameters Init parameters
|
||||
* @param initCompleteCallback Callback used to notify when the initialization is complete.
|
||||
* @return None
|
||||
*/
|
||||
extern void cbBM_init(
|
||||
cbBM_InitParams *pInitParameters,
|
||||
cbBM_InitComplete initCompleteCallback);
|
||||
|
||||
/**
|
||||
* This function sets all default parameters for LE.
|
||||
* This function needs to be called before the cbBM_init.
|
||||
*/
|
||||
extern void cbBM_setDefaultValuesLeParams(void);
|
||||
|
||||
/**
|
||||
* Get the current Bluetooth address of the device.
|
||||
* @param pAddress Pointer to return variable.
|
||||
* @return if the operation is successful cbBM_OK is returned.
|
||||
*/
|
||||
extern cb_int32 cbBM_getLocalAddress(TBdAddr *pAddress);
|
||||
|
||||
/**
|
||||
* Set local name
|
||||
* This sets the Bluetooth Classic device name as well as the Bluetooth Low
|
||||
* Energy device name. Inquiry and advertising is updated.
|
||||
* @param pName The new local name.
|
||||
* @return If the operation is successful cbBM_OK is returned.
|
||||
*/
|
||||
extern cb_int32 cbBM_setLocalName(cb_char* pName);
|
||||
|
||||
/**
|
||||
* Get local name.
|
||||
* Get the current local name.
|
||||
* @param pName Pointer to return variable.
|
||||
* @param length Max length of the name string.
|
||||
* @return If the operation is successful cbBM_OK is returned.
|
||||
*/
|
||||
extern cb_int32 cbBM_getLocalName(
|
||||
cb_char *pName,
|
||||
cb_uint32 length);
|
||||
|
||||
/**
|
||||
* Set class of device
|
||||
* @param cod New Class of Device.
|
||||
* @return If the operation is successful cbBM_OK is returned.
|
||||
*/
|
||||
extern cb_int32 cbBM_setCod(TCod cod);
|
||||
|
||||
/**
|
||||
* Get current class of device.
|
||||
* @param pCod Pointer to return variable.
|
||||
* @return If the operation is successful cbBM_OK is returned.
|
||||
*/
|
||||
extern cb_int32 cbBM_getCod(TCod* pCod);
|
||||
|
||||
/**
|
||||
* Set discoverable mode for Bluetooth Classic.
|
||||
* @param discoverable New discoverable mode.
|
||||
* @return If the operation is successful cbBM_OK is returned.
|
||||
*/
|
||||
extern cb_int32 cbBM_setDiscoverableMode(cbBM_DiscoverableMode discoverable);
|
||||
|
||||
/**
|
||||
* Get current discoverable mode for Bluetooth Classic.
|
||||
* @param pDiscoverable Pointer to return variable.
|
||||
* @return If the operation is successful cbBM_OK is returned.
|
||||
*/
|
||||
extern cb_int32 cbBM_getDiscoverableMode(cbBM_DiscoverableMode *pDiscoverable);
|
||||
|
||||
/**
|
||||
* Set connectable mode for Bluetooth Classic.
|
||||
* @param connectable Connectable mode
|
||||
* @return If the operation is successful cbBM_OK is returned.
|
||||
*/
|
||||
extern cb_int32 cbBM_setConnectableMode(cbBM_ConnectableMode connectable);
|
||||
|
||||
/**
|
||||
* Get current connectable mode for Bluetooth Classic
|
||||
* @param pConnectable Pointer to return variable.
|
||||
* @return If the operation is successful cbBM_OK is returned.
|
||||
*/
|
||||
extern cb_int32 cbBM_getConnectableMode(cbBM_ConnectableMode *pConnectable);
|
||||
|
||||
/**
|
||||
* Set master slave policy for Bluetooth Classic
|
||||
* @param policy Master slave policy
|
||||
* @return If the operation is successful cbBM_OK is returned.
|
||||
*/
|
||||
extern cb_int32 cbBM_setMasterSlavePolicy(TMasterSlavePolicy policy);
|
||||
|
||||
/**
|
||||
* Set master slave policy for Bluetooth Classic
|
||||
* @param pPolicy Pointer to return variable
|
||||
* @return If the operation is successful cbBM_OK is returned.
|
||||
*/
|
||||
extern cb_int32 cbBM_getMasterSlavePolicy(TMasterSlavePolicy *pPolicy);
|
||||
|
||||
/**
|
||||
* Set default channel map for Bluetooth Classic. Used to exclude channels
|
||||
* from usage.
|
||||
* Request an update of which channels shall be used by adaptive frequency hopping.
|
||||
* typically this is not needed since the Bluetooth is very good at select which
|
||||
* channels to use.
|
||||
* @param channelMap Channel map. Note that at least 20 channels must be enabled.
|
||||
* @param channelMapCallback Callback used to notify if the channel map
|
||||
* is accepted by the radio.
|
||||
* @return If the operation is successfully initiated cbBM_OK is returned.
|
||||
*/
|
||||
extern cb_int32 cbBM_setAfhChannelMap(
|
||||
TChannelMap channelMap,
|
||||
cbBM_ChannelMapCallb channelMapCallback);
|
||||
|
||||
/**
|
||||
* Get the default channel map.
|
||||
* @param pMap Pointer to return variable.
|
||||
* @return If the operation is successful cbBM_OK is returned.
|
||||
*/
|
||||
extern cb_int32 cbBM_getAfhChannelMap(TChannelMap *pMap);
|
||||
|
||||
/**
|
||||
* Start an Bluetooth inquiry.
|
||||
* The event callback is called for every device that is found during inquiry.
|
||||
* @param type Type of inquiry.
|
||||
* @param inquiryLengthInMs Length of inquiry in ms
|
||||
* @param eventCallback Callback used to notify each found device
|
||||
* @param completeCallback Callback used to notify when the inquiry is completed
|
||||
* @return If the inquiry is successfully started cbBM_OK is returned
|
||||
*/
|
||||
extern cb_int32 cbBM_inquiry(
|
||||
cbBM_InquiryType type,
|
||||
cb_uint32 inquiryLengthInMs,
|
||||
cbBM_InquiryEventCallback eventCallback,
|
||||
cbBM_InquiryCompleteCallback completeCallback);
|
||||
|
||||
/**
|
||||
* Cancel an ongoing inquiry.
|
||||
* @return If the operation is successful cbBM_OK is returned.
|
||||
*/
|
||||
extern cb_int32 cbBM_inquiryCancel(void);
|
||||
|
||||
/**
|
||||
* Perform a remote name request for Bluetooth Classic.
|
||||
* @param pAddress Pointer to address of remote device.
|
||||
* @param clockOffset Clock offset. Can be found in inquiry response.
|
||||
* @param pageTimeout Page timeout in ms (Length of connection attempt).
|
||||
* @param remoteNameCallb Callback used to notify the the completion of the
|
||||
* name request.
|
||||
* @return If the operation is successfully initiated cbBM_OK is returned.
|
||||
*/
|
||||
extern cb_int32 cbBM_remoteName(
|
||||
TBdAddr *pAddress,
|
||||
cb_uint16 clockOffset,
|
||||
cb_uint16 pageTimeout,
|
||||
cbBM_RemoteNameCallback remoteNameCallb);
|
||||
|
||||
/**
|
||||
* Add service class to inquiry response data. Typically
|
||||
* not used by the application.
|
||||
* @param uuid16 The UUID to add
|
||||
* @return If the operation is successful cbBM_OK is returned.
|
||||
*/
|
||||
extern cb_int32 cbBM_addServiceClass(cb_uint16 uuid16);
|
||||
|
||||
/**
|
||||
* Check if service class is already registered.
|
||||
* @param uuid16 The UUID to check
|
||||
* @return TRUE If the ServiceClass is registered, FALSE otherwise.
|
||||
*/
|
||||
cb_boolean cbBM_isServiceClassRegistered(cb_uint16 uuid16 );
|
||||
|
||||
/**
|
||||
* Add service class to inquiry response data. Typically
|
||||
* not used by the application.
|
||||
* @param uuid128 The UUID to add.
|
||||
* @return If the operation is successful cbBM_OK is returned.
|
||||
*/
|
||||
extern cb_int32 cbBM_add128BitsServiceClass(cb_uint8* uuid128);
|
||||
|
||||
/**
|
||||
* Set maximum Bluetooth Classic ACL links the stack
|
||||
* shall allow.
|
||||
* @param maxConnections Max ACL connections.
|
||||
* @return If the operation is successful cbBM_OK is returned.
|
||||
*/
|
||||
extern cb_int32 cbBM_setMaxConnections(cb_uint32 maxConnections);
|
||||
|
||||
/**
|
||||
* Get controller version string.
|
||||
* @return Pointer to NULL terminated version string.
|
||||
*/
|
||||
extern cb_char* cbBM_getControllerVersionString(void);
|
||||
|
||||
/**
|
||||
* Get stack version string.
|
||||
* @return Pointer to NULL terminated version string.
|
||||
*/
|
||||
extern cb_char* cbBM_getStackVersionString(void);
|
||||
|
||||
/**
|
||||
* Get current Bluetooth Low Energy Role.
|
||||
* @return Current Bluetooth Low Energy role.
|
||||
*/
|
||||
extern cbBM_LeRole cbBM_getLeRole(void);
|
||||
|
||||
/**
|
||||
* Set Bluetooth Low Energy discoverable mode.
|
||||
* Only valid for peripheral role.
|
||||
* @param discoverableMode Bluetooth Low Energy discoverable mode
|
||||
* @return cbBM_OK is returned on success.
|
||||
*/
|
||||
extern cb_int32 cbBM_setDiscoverableModeLe(
|
||||
cbBM_DiscoverableModeLe discoverableMode);
|
||||
|
||||
/**
|
||||
* Get Bluetooth Low Energy discoverable mode.
|
||||
* @param pDiscoverableMode Pointer to return variable
|
||||
* @return cbBM_OK is returned on success.
|
||||
*/
|
||||
extern cb_int32 cbBM_getDiscoverableModeLe(
|
||||
cbBM_DiscoverableModeLe *pDiscoverableMode);
|
||||
|
||||
/**
|
||||
* Set Bluetooth Low Energy connectable mode.
|
||||
* Only valid for peripheral role.
|
||||
* @param connectable Set to TRUE to accept connections
|
||||
* Set to FALSE to reject incoming connections
|
||||
* @return cbBM_OK is returned on success.
|
||||
*/
|
||||
extern cb_int32 cbBM_setConnectableModeLe(
|
||||
cbBM_ConnectableModeLe connectable);
|
||||
|
||||
/**
|
||||
* Get current connectable mode.
|
||||
* @param pConnectable Pointer to return variable.
|
||||
* @return cbBM_OK is returned on success.
|
||||
*/
|
||||
extern cb_int32 cbBM_getConnectableModeLe(
|
||||
cbBM_ConnectableModeLe* pConnectable);
|
||||
|
||||
/**
|
||||
* Set custom advertising data.
|
||||
* Only valid for peripheral role.
|
||||
* @param pAdvData Pointer to advertising data.
|
||||
* @return cbBM_OK is returned on success.
|
||||
*/
|
||||
extern cb_int32 cbBM_setCustomAdvData(
|
||||
TAdvData* pAdvData);
|
||||
|
||||
/**
|
||||
* Set custom scan response data.
|
||||
* Only valid for peripheral role.
|
||||
* @param pScanRspData Pointer to scan response data.
|
||||
* @return cbBM_OK is returned on success.
|
||||
*/
|
||||
extern cb_int32 cbBM_setCustomScanRspData(
|
||||
TAdvData* pScanRspData);
|
||||
|
||||
/**
|
||||
* Set current scan response data.
|
||||
* Only valid for peripheral role.
|
||||
* @param pAdvData Pointer to scan response data.
|
||||
* @return cbBM_OK is returned on success.
|
||||
*/
|
||||
extern cb_int32 cbBM_getAdvData(
|
||||
TAdvData* pAdvData);
|
||||
|
||||
/**
|
||||
* Get current scan response data.
|
||||
* Only valid for peripheral role.
|
||||
* @param pScanRspData Pointer to scan response data.
|
||||
* @return cbBM_OK is returned on success.
|
||||
*/
|
||||
extern cb_int32 cbBM_getScanRspData(
|
||||
TAdvData* pScanRspData);
|
||||
|
||||
/**
|
||||
* Set default Bluetooth Low Energy connection parameters.
|
||||
* Note that setting the connection parameters does not change
|
||||
* the parameters on active connections.
|
||||
* @param createConnectionTimeout Default timeout connection for connection attempts
|
||||
* @param connIntervalMin Default connection min interval
|
||||
* @param connIntervalMax Default connection max interval
|
||||
* @param connLatency Default connection latency
|
||||
* @param linklossTmo Default link loss timeout
|
||||
* @return cbBM_OK is returned on success.
|
||||
*/
|
||||
cb_int32 cbBM_setAutoConnectionParams(
|
||||
cb_uint32 createConnectionTimeout,
|
||||
cb_uint16 connIntervalMin,
|
||||
cb_uint16 connIntervalMax,
|
||||
cb_uint16 connLatency,
|
||||
cb_uint16 linklossTmo);
|
||||
|
||||
/**
|
||||
* Get default Bluetooth Low Energy connection parameters.
|
||||
* @param pCreateConnectionTimeout Default create connection timeout
|
||||
* @param pConnIntervalMin Default connection min interval
|
||||
* @param pConnIntervalMax Default connection max interval
|
||||
* @param pConnLatency Default connection latency
|
||||
* @param pLinklossTmo Default link loss timeout
|
||||
* @return cbBM_OK is returned on success.
|
||||
*/
|
||||
cb_int32 cbBM_getAutoConnectionParams(
|
||||
cb_uint32 *pCreateConnectionTimeout,
|
||||
cb_uint16 *pConnIntervalMin,
|
||||
cb_uint16 *pConnIntervalMax,
|
||||
cb_uint16 *pConnLatency,
|
||||
cb_uint16 *pLinklossTmo);
|
||||
|
||||
/**
|
||||
* Get Bluetooth Low Energy scan parameters.
|
||||
* @param pScanInterval Scan interval
|
||||
* @param pScanWindow Scan window
|
||||
* @return cbBM_OK is returned on success.
|
||||
*/
|
||||
extern cb_int32 cbBM_getAutoconnScanParams(
|
||||
cb_uint16 *pScanInterval,
|
||||
cb_uint16 *pScanWindow);
|
||||
|
||||
/**
|
||||
* Start an Bluetooth Low Energy device discovery.
|
||||
* The event callback is called for every device that is found during inquiry.
|
||||
* @param type Type of discovery.
|
||||
* @param discoveryLength Length of inquiry in seconds.
|
||||
* @param scanType Active or passive scan
|
||||
* @param eventCallback Callback used to notify each found device
|
||||
* @param completeCallback Callback used to notify when the inquiry is completed.
|
||||
* @return If the device discovery is successfully started cbBM_OK is returned.
|
||||
*/
|
||||
extern cb_int32 cbBM_deviceDiscoveryLe(
|
||||
cbBM_DeviceDiscoveryTypeLe type,
|
||||
cb_uint16 discoveryLength,
|
||||
cbBM_ScanTypeLe scanType,
|
||||
cbBM_DeviceDiscoveryLeEventCallback eventCallback,
|
||||
cbBM_DeviceDiscoveryLeCompleteCallback completeCallback);
|
||||
|
||||
/**
|
||||
* Cancel an ongoing device discovery.
|
||||
* @return If the operation is successful cbBM_OK is returned.
|
||||
*/
|
||||
extern cb_int32 cbBM_deviceDiscoveryLeCancel(void);
|
||||
|
||||
/**
|
||||
* Perform a remote name request for Bluetooth Low Energy.
|
||||
* @param pAddress Pointer to address of remote device.
|
||||
* @param remoteNameCallback Callback used to notify the the completion of the
|
||||
* name request.
|
||||
* @return If the operation is successfully initiated cbBM_OK is returned.
|
||||
*/
|
||||
extern cb_int32 cbBM_remoteNameLe(TBdAddr *pAddress,
|
||||
cbBM_RemoteNameCallback remoteNameCallback);
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Add 128bit service UUID to scan response data. Typically
|
||||
* not used by the application.
|
||||
* @param uuid128 Pointer to 128bit UUID
|
||||
* @return If the operation is successfully initiated cbBM_OK is returned.
|
||||
*/
|
||||
extern cb_int32 cbBM_add128BitsServiceClassLe(cb_uint8* uuid128);
|
||||
|
||||
/*
|
||||
* Read the used max tx power .
|
||||
* @return max tx power level as int8.
|
||||
*/
|
||||
extern cb_int8 cbBM_getMaxTxPower(void);
|
||||
|
||||
/*
|
||||
* Read the connection parameters for Bond.
|
||||
* @return cbCMLE_AclParamsLe pointer to values.
|
||||
*/
|
||||
void cbBM_getBondParameters(TAclParamsLe* bondParams);
|
||||
/*
|
||||
* Read the connection parameters for connection.
|
||||
* @return cbCMLE_AclParamsLe pointer to values.
|
||||
*/
|
||||
void cbBM_getConnectParameters(TAclParamsLe* aclParams);
|
||||
/*
|
||||
* Read the connection parameters for remote name request.
|
||||
* @return cbCMLE_AclParamsLe pointer to values.
|
||||
*/
|
||||
void cbBM_getRemoteNameReqParameters(TAclParamsLe* aclParams);
|
||||
|
||||
/*
|
||||
* Sets the LE parameter.
|
||||
* @newValue new parameter value.
|
||||
*/
|
||||
extern cb_int32 cbBM_setAdvertisingIntervalMin(cb_uint16 newValue);
|
||||
extern cb_int32 cbBM_setAdvertisingIntervalMax(cb_uint16 newValue);
|
||||
extern cb_int32 cbBM_setAdvChannelmap(cb_uint16 newValue);
|
||||
extern cb_int32 cbBM_setConnectConnIntervalMin(cb_uint16 newValue);
|
||||
extern cb_int32 cbBM_setConnectConnIntervalMax(cb_uint16 newValue);
|
||||
extern cb_int32 cbBM_setConnectConnLatency(cb_uint16 newValue);
|
||||
extern cb_int32 cbBM_setConnectLinklossTmo(cb_uint16 newValue);
|
||||
extern cb_int32 cbBM_setConnectCreateConnTmo(cb_uint16 newValue);
|
||||
extern cb_int32 cbBM_setConnectScanInterval(cb_uint16 newValue);
|
||||
extern cb_int32 cbBM_setConnectScanWindow(cb_uint16 newValue);
|
||||
extern cb_int32 cbBM_setBondConnIntervalMin(cb_uint16 newValue);
|
||||
extern cb_int32 cbBM_setBondConnIntervalMax(cb_uint16 newValue);
|
||||
extern cb_int32 cbBM_setBondConnLatency(cb_uint16 newValue);
|
||||
extern cb_int32 cbBM_setBondLinklossTmo(cb_uint16 newValue);
|
||||
extern cb_int32 cbBM_setBondCreateConnTmo(cb_uint16 newValue);
|
||||
extern cb_int32 cbBM_setBondScanInterval(cb_uint16 newValue);
|
||||
extern cb_int32 cbBM_setBondScanWindow(cb_uint16 newValue);
|
||||
extern cb_int32 cbBM_setRemoteNameConnIntervalMin(cb_uint16 newValue);
|
||||
extern cb_int32 cbBM_setRemoteNameConnIntervalMax(cb_uint16 newValue);
|
||||
extern cb_int32 cbBM_setRemoteNameConnLatency(cb_uint16 newValue);
|
||||
extern cb_int32 cbBM_setRemoteNameLinklossTmo(cb_uint16 newValue);
|
||||
extern cb_int32 cbBM_setRemoteNameCreateConnTmo(cb_uint16 newValue);
|
||||
extern cb_int32 cbBM_setRemoteNameScanInterval(cb_uint16 newValue);
|
||||
extern cb_int32 cbBM_setRemoteNameScanWindow(cb_uint16 newValue);
|
||||
|
||||
/*
|
||||
* Read the LE parameter.
|
||||
* @return parameter.
|
||||
*/
|
||||
extern cb_uint16 cbBM_getAdvertisingIntervalMin(void);
|
||||
extern cb_uint16 cbBM_getAdvertisingIntervalMax(void);
|
||||
extern cb_uint16 cbBM_getAdvChannelmap(void);
|
||||
extern cb_uint16 cbBM_getConnectConnIntervalMin(void);
|
||||
extern cb_uint16 cbBM_getConnectConnIntervalMax(void);
|
||||
extern cb_uint16 cbBM_getConnectConnLatency(void);
|
||||
extern cb_uint16 cbBM_getConnectLinklossTmo(void);
|
||||
extern cb_uint16 cbBM_getConnectCreateConnTmo(void);
|
||||
extern cb_uint16 cbBM_getConnectScanInterval(void);
|
||||
extern cb_uint16 cbBM_getConnectScanWindow(void);
|
||||
extern cb_uint16 cbBM_getBondConnIntervalMin(void);
|
||||
extern cb_uint16 cbBM_getBondConnIntervalMax(void);
|
||||
extern cb_uint16 cbBM_getBondConnLatency(void);
|
||||
extern cb_uint16 cbBM_getBondLinklossTmo(void);
|
||||
extern cb_uint16 cbBM_getBondCreateConnTmo(void);
|
||||
extern cb_uint16 cbBM_getBondScanInterval(void);
|
||||
extern cb_uint16 cbBM_getBondScanWindow(void);
|
||||
extern cb_uint16 cbBM_getRemoteNameConnIntervalMin(void);
|
||||
extern cb_uint16 cbBM_getRemoteNameConnIntervalMax(void);
|
||||
extern cb_uint16 cbBM_getRemoteNameConnLatency(void);
|
||||
extern cb_uint16 cbBM_getRemoteNameLinklossTmo(void);
|
||||
extern cb_uint16 cbBM_getRemoteNameCreateConnTmo(void);
|
||||
extern cb_uint16 cbBM_getRemoteNameScanInterval(void);
|
||||
extern cb_uint16 cbBM_getRemoteNameScanWindow(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -0,0 +1,142 @@
|
|||
/**
|
||||
*---------------------------------------------------------------------------
|
||||
* Copyright (c) 2016, u-blox Malmö, All Rights Reserved
|
||||
* SPDX-License-Identifier: LicenseRef-PBL
|
||||
*
|
||||
* This file and the related binary are licensed under the
|
||||
* Permissive Binary License, Version 1.0 (the "License");
|
||||
* you may not use these files except in compliance with the License.
|
||||
*
|
||||
* You may obtain a copy of the License here:
|
||||
* LICENSE-permissive-binary-license-1.0.txt and at
|
||||
* https://www.mbed.com/licenses/PBL-1.0
|
||||
*
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* Component : Bluetooth Serial
|
||||
* File : cb_bt_pan.h
|
||||
*
|
||||
* Description : Data management for PAN profile
|
||||
*
|
||||
*-------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef _CB_BT_PAN_H_
|
||||
#define _CB_BT_PAN_H_
|
||||
|
||||
#include "cb_comdefs.h"
|
||||
#include "bt_types.h"
|
||||
#include "cb_bt_conn_man.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*===========================================================================
|
||||
* DEFINES
|
||||
*=========================================================================*/
|
||||
#define cbBTPAN_RESULT_OK ((cb_int32)0x00000000)
|
||||
#define cbBTPAN_RESULT_ERROR ((cb_int32)0x00000001)
|
||||
#define cbBTPAN_RESULT_ILLEGAL_HANDLE ((cb_int32)0x00000002)
|
||||
#define cbBTPAN_RESULT_FLOW_STOP ((cb_int32)0x00000003)
|
||||
#define cbBTPAN_RESULT_LINK_LOSS ((cb_int32)0x00000004)
|
||||
|
||||
/*===========================================================================
|
||||
* TYPES
|
||||
*=========================================================================*/
|
||||
typedef cb_uint32 cbBTPAN_Handle;
|
||||
|
||||
/*---------------------------------------------------------------------------
|
||||
* Callback to indicate that a Bnep connection has been established.
|
||||
*
|
||||
* @param connHandle: Connection handle
|
||||
* @param info: Information about the connection
|
||||
*
|
||||
* @return None
|
||||
*-------------------------------------------------------------------------*/
|
||||
typedef void(*cbBTPAN_ConnectEvt) (cbBCM_Handle connHandle, cbBCM_ConnectionInfo info);
|
||||
|
||||
/*---------------------------------------------------------------------------
|
||||
* Callback to indicate that a Bnep connection has been disconnected.
|
||||
*
|
||||
* @param connHandle: Connection handle
|
||||
*
|
||||
* @return None
|
||||
*-------------------------------------------------------------------------*/
|
||||
typedef void(*cbBTPAN_DisconnectEvt) (cbBCM_Handle connHandle);
|
||||
|
||||
/*---------------------------------------------------------------------------
|
||||
* Callback to indicate that data has been received from remote device.
|
||||
*
|
||||
* @param btPanHandle: PAN handle
|
||||
* @param length: Length of the data
|
||||
* @param pData: Pointer to the data
|
||||
*
|
||||
* @return None
|
||||
*-------------------------------------------------------------------------*/
|
||||
typedef void(*cbBTPAN_DataEvt) (cbBCM_Handle connHandle, cb_uint8* pData, cb_uint16 length);
|
||||
|
||||
/*---------------------------------------------------------------------------
|
||||
* Callback to indicate that data has been taken care by PAN. New
|
||||
* data can now be sent on this handle.
|
||||
*
|
||||
* @param btPanHandle: PAN handle
|
||||
* @param result: cbBTPAN_RESULT_OK if the data sending succeeded
|
||||
*
|
||||
* @return None
|
||||
*-------------------------------------------------------------------------*/
|
||||
typedef void(*cbBTPAN_DataCnf) (cbBCM_Handle connHandle, cb_int32 result);
|
||||
|
||||
typedef struct
|
||||
{
|
||||
cbBTPAN_ConnectEvt pfConnectEvt;
|
||||
cbBTPAN_DisconnectEvt pfDisconnectEvt;
|
||||
cbBTPAN_DataEvt pfDataEvt;
|
||||
cbBTPAN_DataCnf pfWriteCnf;
|
||||
}cbBTPAN_Callback;
|
||||
|
||||
/*===========================================================================
|
||||
* FUNCTIONS
|
||||
*=========================================================================*/
|
||||
/**
|
||||
* Initialization of Bluetooth PAN data. Called during stack
|
||||
* initialization. Shall not be called by application.
|
||||
*
|
||||
* @return None
|
||||
*/
|
||||
extern void cbBTPAN_init(void);
|
||||
|
||||
/**
|
||||
* Registers for PAN data callbacks. Only one registration is supported.
|
||||
*
|
||||
* @param pDataCallback Data callback
|
||||
*
|
||||
* @return cbBTPAN_RESULT_OK if successful
|
||||
*/
|
||||
extern cb_uint32 cbBTPAN_registerDataCallback(cbBTPAN_Callback* pDataCallback);
|
||||
|
||||
/*---------------------------------------------------------------------------
|
||||
* Sends data to the remote device. Note that you have to wait for the
|
||||
* confirmation callback (cbBTPAN_DataCnf) before calling another cbBTPAN_reqData.
|
||||
*
|
||||
* @param connHandle: Connection handle
|
||||
* @param pBuf: Pointer to the data
|
||||
* @param bufSize: Length of the data
|
||||
*
|
||||
* @return cbBTPAN_RESULT_OK if successful
|
||||
*-------------------------------------------------------------------------*/
|
||||
extern cb_int32 cbBTPAN_reqData(cbBCM_Handle connHandle, cb_uint8* pBuf, cb_uint16 bufSize);
|
||||
|
||||
/*---------------------------------------------------------------------------
|
||||
* Gets the max frame size that can be sent/received with
|
||||
* cbBTPAN_reqData/pfDataEvt
|
||||
*
|
||||
* @return max frame size
|
||||
*-------------------------------------------------------------------------*/
|
||||
extern cb_int32 cbBTPAN_getMaxFrameSize(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif //_cb_BT_PAN_H_
|
|
@ -0,0 +1,378 @@
|
|||
/*---------------------------------------------------------------------------
|
||||
* Copyright (c) 2016, u-blox Malmö, All Rights Reserved
|
||||
* SPDX-License-Identifier: LicenseRef-PBL
|
||||
*
|
||||
* This file and the related binary are licensed under the
|
||||
* Permissive Binary License, Version 1.0 (the "License");
|
||||
* you may not use these files except in compliance with the License.
|
||||
*
|
||||
* You may obtain a copy of the License here:
|
||||
* LICENSE-permissive-binary-license-1.0.txt and at
|
||||
* https://www.mbed.com/licenses/PBL-1.0
|
||||
*
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* Component : Bluetooth Security Manager
|
||||
* File : cb_bt_sec_man.h
|
||||
*
|
||||
* Description : Bluetooth security application support
|
||||
*-------------------------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
* @file cb_bt_sec_man.h
|
||||
* @brief Bluetooth security application support. This includes bonding,
|
||||
* security modes, passkey and pin code handling.
|
||||
*/
|
||||
|
||||
#ifndef _CB_BT_SEC_MAN_H_
|
||||
#define _CB_BT_SEC_MAN_H_
|
||||
|
||||
#include "cb_comdefs.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*===========================================================================
|
||||
* DEFINES
|
||||
*=========================================================================*/
|
||||
#define cbBSM_OK (0)
|
||||
#define cbBSM_ERROR (-1)
|
||||
|
||||
#define cbBSM_PASSKEY_MAX_VALUE (999999)
|
||||
|
||||
/*===========================================================================
|
||||
* TYPES
|
||||
*=========================================================================*/
|
||||
|
||||
/**
|
||||
* cbBSM_SECURITY_MODE_1_DISABLED
|
||||
* Security disabled
|
||||
* - Remote Device BT 2.1: Auto accept (No man-in-the-middle attack protection, encryption enabled)
|
||||
* - Remote Device BT 2.0: Authentication and encryption disabled.
|
||||
* - Bluetooth Low Energy: Auto accept (No man-in-the-middle attack protection, encryption enabled)
|
||||
*
|
||||
* cbBSM_SECURITY_MODE_2_BT_2_0
|
||||
* - Enforce BT 2.0 (Service level authentication and encryption enabled)
|
||||
* Please note that the device is not BT 2.1 qualified for this setting. It is included for backward compatibility. Invalid for Bluetooth Low Energy.
|
||||
*
|
||||
* cbBSM_SECURITY_MODE_3_FIXED_PIN
|
||||
* - Remote Device BT 2.1: Service level authentication and encryption enabled.
|
||||
* - Remote Device BT 2.0: Service level authentication and encryption enabled.
|
||||
* - Bluetooth Low Energy: Service level authentication and encryption enabled.
|
||||
* Please note that this security mode will not work with a general BT 2.1 device. However, it will work between two connectBlue BT 2.1 Serial Port Adapters. Use security mode 4 to make the device work with a general BT 2.1 device.
|
||||
*
|
||||
* cbBSM_SECURITY_MODE_4_JUST_WORKS
|
||||
* - Remote Device BT 2.1: Auto accept (no man-in-the-middle attack protection, encryption enabled)
|
||||
* - Remote Device BT 2.0: Service level authentication and encryption enabled.
|
||||
* - Bluetooth Low Energy: Auto accept (no man-in-the-middle attack protection, encryption enabled)
|
||||
* This security mode is intended for pairing in safe environments. When this mode is set, pairability (see AT*AGPM) is automatically disabled. In data mode, pairing can be enabled for 60 seconds by pressing the "External Connect" button for at least 5 seconds. When the module is pairable, the LED will blink. If the mode is changed from Just Works to another, pairability must be enabled again using the AT*AGPM command.
|
||||
*
|
||||
* cbBSM_SECURITY_MODE_5_DISPLAY_ONLY
|
||||
* - Remote Device BT 2.1: Service level authentication and encryption enabled. User should be presented a passkey.
|
||||
* - Remote Device BT 2.0: Service level authentication and encryption enabled. No user interaction required.
|
||||
* - Bluetooth Low Energy: Service level authentication and encryption enabled. User should be presented a passkey.
|
||||
* This security mode is used when the device has a display that can present a 6-digit value that the user shall enter on the remote device.
|
||||
*
|
||||
* cbBSM_SECURITY_MODE_6_DISPLAY_YES_NO
|
||||
* - Remote Device BT 2.1: Service level authentication and encryption enabled. User should compare two values.
|
||||
* - Remote Device BT 2.0: Service level authentication and encryption enabled. No user interaction required.
|
||||
* This security mode is used when the device has a display that can present a 6-digit value that the user shall verify with yes or no to the remote device's presented value.
|
||||
* Invalid for Bluetooth Low Energy.
|
||||
*
|
||||
* cbBSM_SECURITY_MODE_7_KEYBOARD_ONLY
|
||||
* - Remote Device BT 2.1: Service level authentication and encryption enabled. User should enter a passkey.
|
||||
* - Remote Device BT 2.0: Service level authentication and encryption enabled. No user interaction required.
|
||||
* - Bluetooth Low Energy: Service level authentication and encryption enabled. User should enter a passkey.
|
||||
* This security mode is used when the device only has a keyboard where the user can enter a 6-digit value that is presented on the remote device.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
cbBSM_SECURITY_MODE_1_DISABLED = 1,
|
||||
cbBSM_SECURITY_MODE_2_BT_2_0,
|
||||
cbBSM_SECURITY_MODE_3_FIXED_PIN,
|
||||
cbBSM_SECURITY_MODE_4_JUST_WORKS,
|
||||
cbBSM_SECURITY_MODE_5_DISPLAY_ONLY,
|
||||
cbBSM_SECURITY_MODE_6_DISPLAY_YES_NO,
|
||||
cbBSM_SECURITY_MODE_7_KEYBOARD_ONLY
|
||||
} cbBSM_SecurityMode;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
TPinCode pin;
|
||||
cb_uint8 nBytes;
|
||||
} cbBSM_PinCode;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
cbBSM_BOND_TYPE_CLASSIC,
|
||||
cbBSM_BOND_TYPE_LE,
|
||||
cbBSM_BOND_TYPE_ALL,
|
||||
} cbBSM_BondTypes;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
cbBSM_BOND_STATUS_OK = 0,
|
||||
cbBSM_BOND_STATUS_ERR_PAGE_TMO,
|
||||
cbBSM_BOND_STATUS_ERR_AUTH_FAIL,
|
||||
cbBSM_BOND_STATUS_ERR_NO_MITM
|
||||
} cbBSM_BondStatus;
|
||||
|
||||
/**
|
||||
* Callback to indicate that bonding is finished.
|
||||
* @param bdAddress Remote BD address
|
||||
* @param bondStatus Bond status, e.g. cbBSM_BOND_STATUS_OK
|
||||
* @return None
|
||||
*/
|
||||
typedef void (*cbBSM_BondCnf)(
|
||||
cbBSM_BondStatus status,
|
||||
TBdAddr* pBdAddress);
|
||||
|
||||
/**
|
||||
* Callback to indicate that a pin code is required from upper layer.
|
||||
* Respond the pin code request with cbBSM_rspFixedPin/cbBSM_rspNegFixedPin
|
||||
* This is only used when either local or remote side does not support
|
||||
* BT 2.1 secure simple pairing.
|
||||
* @param bdAddress Remote BD address
|
||||
* @return None
|
||||
*/
|
||||
typedef void (*cbBSM_RequestPinInd)(
|
||||
TBdAddr* pBdAddress);
|
||||
|
||||
/**
|
||||
* Callback to indicate that user confirmation is required. The user should
|
||||
* compare numericValues on local and remote side and respond the confirmation
|
||||
* request with cbBSM_rspUserConfirmation if values match and
|
||||
* cbBSM_rspNegUserConfirmation if they do not match or user wants to interrupt
|
||||
* the pairing attempt.
|
||||
* This is only used when both sides support BT 2.1 secure simple pairing and
|
||||
* security mode cbBSM_SECURITY_MODE_6_DISPLAY_YES_NO is used.
|
||||
* @param bdAddress Remote BD address
|
||||
* @param numericValue The numeric value to be compared
|
||||
* @return None
|
||||
*/
|
||||
typedef void (*cbBSM_UserConfirmationInd)(
|
||||
TBdAddr* pBdAddress,
|
||||
cb_uint32 numericValue);
|
||||
|
||||
/**
|
||||
* Callback to indicate that a passkey is required from upper layer.
|
||||
* Respond the passkey request with cbBSM_rspUserPasskey/cbBSM_rspNegUserPasskey.
|
||||
* This is only used when both sides support BT 2.1 secure simple pairing and
|
||||
* security modes cbBSM_SECURITY_MODE_3_FIXED_PIN or cbBSM_SECURITY_MODE_7_KEYBOARD_ONLY is used
|
||||
* @param bdAddress Remote BD address
|
||||
* @return None
|
||||
*/
|
||||
typedef void (*cbBSM_UserPasskeyInd)(
|
||||
TBdAddr* pBdAddress);
|
||||
|
||||
/**
|
||||
* Callback to indicate that a passkey is used in the pairing procedure.
|
||||
* The passkey should be displayed to the user.
|
||||
* This is only used when both sides support BT 2.1 secure simple pairing and
|
||||
* security mode cbBSM_SECURITY_MODE_5_DISPLAY_ONLY is used.
|
||||
* @param bdAddress Remote BD address
|
||||
* @param passkey Passkey
|
||||
* @return None
|
||||
*/
|
||||
typedef void (*cbBSM_UserPasskeyEvt)(
|
||||
TBdAddr* pBdAddress,
|
||||
cb_uint32 passkey);
|
||||
|
||||
typedef struct
|
||||
{
|
||||
cbBSM_RequestPinInd requestPinInd;
|
||||
cbBSM_UserConfirmationInd userConfirmationInd;
|
||||
cbBSM_UserPasskeyInd userPasskeyInd;
|
||||
cbBSM_UserPasskeyEvt userPasskeyEvt;
|
||||
cbBSM_BondCnf bondConfirmation;
|
||||
cbBSM_BondCnf bondEvent;
|
||||
} cbBSM_Callbacks;
|
||||
|
||||
/*===========================================================================
|
||||
* FUNCTIONS
|
||||
*=========================================================================*/
|
||||
|
||||
/**
|
||||
* Initialization of BLuetooth security manager. Called during stack
|
||||
* initialization. Shall not be called by application.
|
||||
*
|
||||
* @return None
|
||||
*/
|
||||
extern void cbBSM_init(void);
|
||||
|
||||
/**
|
||||
* Register security callbacks. Callbacks in the struct that are not
|
||||
* of any interest can be set to NULL.
|
||||
*
|
||||
* @param pPairingCallbacks Pointer to the security callback struct
|
||||
* @return If the operation is successful cbBSM_OK is returned.
|
||||
*/
|
||||
extern cb_int32 cbBSM_registerCallbacks(cbBSM_Callbacks* pPairingCallbacks);
|
||||
|
||||
/**
|
||||
* Set security mode. See comments on cbBSM_SecurityMode for
|
||||
* description of the different security modes.
|
||||
*
|
||||
* @param securityMode Security mode. Default security is cbBSM_SECURITY_MODE_1_DISABLED
|
||||
* @param allowPairingInNonBondableMode Normally FALSE. Set to TRUE if pairing should be allowed when not bondable.
|
||||
* No link keys will then be stored.
|
||||
* @return If the operation is successful cbBSM_OK is returned.
|
||||
*/
|
||||
extern cb_int32 cbBSM_setSecurityMode(
|
||||
cbBSM_SecurityMode securityMode,
|
||||
cb_boolean allowPairingInNonBondableMode);
|
||||
|
||||
/**
|
||||
* Read current security mode.
|
||||
*
|
||||
* @param pSecurityMode Security mode
|
||||
* @return If the operation is successful cbBSM_OK is returned.
|
||||
*/
|
||||
extern cb_int32 cbBSM_getSecurityMode(cbBSM_SecurityMode* pSecurityMode);
|
||||
|
||||
/**
|
||||
* Sets the local device pairable mode.
|
||||
*
|
||||
* @param pairable TRUE=pairable, FALSE=not pairable (default)
|
||||
* @return If the operation is successful cbBSM_OK is returned.
|
||||
*/
|
||||
extern cb_int32 cbBSM_setPairable(boolean pairable);
|
||||
|
||||
/**
|
||||
* Gets the local device pairable mode.
|
||||
*
|
||||
* @param pPairable Pointer to return value
|
||||
* @return If the operation is successful cbBSM_OK is returned.
|
||||
*/
|
||||
extern cb_int32 cbBSM_getPairable(boolean* pPairable);
|
||||
|
||||
/**
|
||||
* Performs bonding with a remote device. The cbBSM_BondCnf callback will
|
||||
* be called upon success/failure.
|
||||
*
|
||||
* @param remoteDevice Remote BD address
|
||||
* @param type Classic or LE
|
||||
* @return If the operation is successful cbBSM_OK is returned.
|
||||
*/
|
||||
extern cb_int32 cbBSM_reqBond(
|
||||
TBdAddr remoteDevice,
|
||||
TBluetoothType type);
|
||||
|
||||
/**
|
||||
* Responds on the cbBSM_RequestPinInd callback with a pin code
|
||||
* This is only used when either local or remote side does not support
|
||||
* BT 2.1 secure simple pairing.
|
||||
*
|
||||
* @param pBdAddress Pointer to the remote BD address
|
||||
* @param pinCodeLength Length of the provided pin code
|
||||
* @param pPinCode Pointer to the provided pin code
|
||||
* @return If the operation is successful cbBSM_OK is returned.
|
||||
*/
|
||||
extern cb_int32 cbBSM_rspFixedPin(
|
||||
TBdAddr* pBdAddress,
|
||||
cb_uint8 pinCodeLength,
|
||||
cb_uint8 *pPinCode);
|
||||
|
||||
/**
|
||||
* Responds the cbBSM_RequestPinInd callback. Can be used to interrupt a
|
||||
* pairing attempt from the remote device.
|
||||
* This is only used when either local or remote side does not support
|
||||
* BT 2.1 secure simple pairing.
|
||||
*
|
||||
* @param pBdAddress Pointer to the remote BD address
|
||||
* @return If the operation is successful cbBSM_OK is returned.
|
||||
*/
|
||||
extern cb_int32 cbBSM_rspNegFixedPin(TBdAddr* pBdAddress);
|
||||
|
||||
/**
|
||||
* Responds on the cbBSM_UserPasskeyInd callback.
|
||||
* This is only used when both sides support BT 2.1 secure simple pairing.
|
||||
*
|
||||
* @param pBdAddress Pointer to the remote BD address
|
||||
* @param passkey Passkey, range: 0-999999
|
||||
* @return If the operation is successful cbBSM_OK is returned.
|
||||
*/
|
||||
extern cb_int32 cbBSM_rspUserPasskey(
|
||||
TBdAddr *pBdAddress,
|
||||
uint32 passkey);
|
||||
|
||||
/**
|
||||
* Responds on the cbBSM_UserPasskeyInd callback. Can be used to interrupt a
|
||||
* pairing attempt from the remote device.
|
||||
* This is only used when both sides support BT 2.1 secure simple pairing.
|
||||
*
|
||||
* @param pBdAddress Pointer to the remote BD address
|
||||
* @return If the operation is successful cbBSM_OK is returned.
|
||||
*/
|
||||
extern cb_int32 cbBSM_rspNegUserPasskey(TBdAddr *pBdAddress);
|
||||
|
||||
/**
|
||||
* Responds on the cbBSM_UserConfirmationInd callback. Accepts the numeric value.
|
||||
* This is only used when both sides support BT 2.1 secure simple pairing.
|
||||
*
|
||||
* @param pBdAddress Pointer to the remote BD address
|
||||
* @return If the operation is successful cbBSM_OK is returned.
|
||||
*/
|
||||
extern cb_int32 cbBSM_rspUserConfirmation(TBdAddr* pBdAddress);
|
||||
|
||||
/**
|
||||
* Responds on the cbBSM_UserConfirmationInd callback. Rejects the numeric value.
|
||||
* This is only used when both sides support BT 2.1 secure simple pairing.
|
||||
*
|
||||
* @param pBdAddress Pointer to the remote BD address
|
||||
* @return If the operation is successful cbBSM_OK is returned.
|
||||
*/
|
||||
extern cb_int32 cbBSM_rspNegUserConfirmation(TBdAddr* pBdAddress);
|
||||
|
||||
/**
|
||||
* Get number of bonded devices.
|
||||
*
|
||||
* @param type Bond type
|
||||
* @param pNo Pointer to return value.
|
||||
* @return If the operation is successful cbBSM_OK is returned.
|
||||
*/
|
||||
extern cb_int32 cbBSM_getAllNumberBondedDevices(
|
||||
cbBSM_BondTypes type,
|
||||
uint32* pNo);
|
||||
|
||||
/**
|
||||
* Get a bonded devices.
|
||||
*
|
||||
* @param deviceIndex Index of the bonded device
|
||||
* @param pBdAddr Pointer to remote BD address.
|
||||
* @param pIsLe Should be TRUE for LE and FALSE for classic
|
||||
* @return If the operation is successful cbBSM_OK is returned.
|
||||
*/
|
||||
extern cb_int32 cbBSM_getBondedDevice(
|
||||
uint32 deviceIndex,
|
||||
TBdAddr* pBdAddr,
|
||||
cb_boolean pIsLe);
|
||||
|
||||
/**
|
||||
* Delete a bonded device and its link keys.
|
||||
*
|
||||
* @param pBdAddress to the address of the device which bond shall be deleted.
|
||||
* @return If the operation is successful cbBSM_OK is returned.
|
||||
*/
|
||||
extern cb_int32 cbBSM_deleteBondedDevice(TBdAddr* pBdAddress);
|
||||
|
||||
/**
|
||||
* Delete all bonded devices and link keys.
|
||||
*
|
||||
* @return If the operation is successful cbBSM_OK is returned.
|
||||
*/
|
||||
extern cb_int32 cbBSM_deleteAllBondedDevices(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _CB_BT_SEC_MAN_H_ */
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,155 @@
|
|||
/**
|
||||
*---------------------------------------------------------------------------
|
||||
* Copyright (c) 2016, u-blox Malmö, All Rights Reserved
|
||||
* SPDX-License-Identifier: LicenseRef-PBL
|
||||
*
|
||||
* This file and the related binary are licensed under the
|
||||
* Permissive Binary License, Version 1.0 (the "License");
|
||||
* you may not use these files except in compliance with the License.
|
||||
*
|
||||
* You may obtain a copy of the License here:
|
||||
* LICENSE-permissive-binary-license-1.0.txt and at
|
||||
* https://www.mbed.com/licenses/PBL-1.0
|
||||
*
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* Component : Bluetooth Serial
|
||||
* File : cb_bt_serial.h
|
||||
*
|
||||
* Description : Data management for RFCOMM based profiles such and Serial
|
||||
* Port Profile (SPP).
|
||||
*
|
||||
*-------------------------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
* @file cb_bt_serial.h
|
||||
* @brief Data management for RFCOMM based profiles such and Serial
|
||||
* Port Profile (SPP).
|
||||
*/
|
||||
|
||||
#ifndef _CB_BT_SERIAL_H_
|
||||
#define _CB_BT_SERIAL_H_
|
||||
|
||||
#include "cb_comdefs.h"
|
||||
#include "bt_types.h"
|
||||
#include "cb_bt_conn_man.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*===========================================================================
|
||||
* DEFINES
|
||||
*=========================================================================*/
|
||||
#define cbBSE_OK 0
|
||||
#define cbBSE_ERROR -1
|
||||
#define cbBSE_NO_DATA -2
|
||||
|
||||
/*===========================================================================
|
||||
* TYPES
|
||||
*=========================================================================*/
|
||||
|
||||
typedef void (*cbBSE_DataAvailEvt)(
|
||||
cbBCM_Handle handle);
|
||||
|
||||
typedef void (*cbBSE_WriteCnf)(
|
||||
cbBCM_Handle handle,
|
||||
cb_int32 status,
|
||||
cb_uint32 nBytes,
|
||||
cb_int32 tag);
|
||||
|
||||
typedef struct
|
||||
{
|
||||
cbBSE_DataAvailEvt pfDataEvt;
|
||||
cbBSE_WriteCnf pfWriteCnf;
|
||||
}cbBSE_Callback;
|
||||
|
||||
/*===========================================================================
|
||||
* FUNCTIONS
|
||||
*=========================================================================*/
|
||||
/**
|
||||
* Initialization of Bluetooth serial manager. Called during stack
|
||||
* initialization. Shall not be called by application.
|
||||
*
|
||||
* @return None
|
||||
*/
|
||||
extern void cbBSE_init(void);
|
||||
|
||||
/**
|
||||
* Open a data channel.
|
||||
*
|
||||
* @param handle Connection handle
|
||||
* @param pCallback Callback for data events.
|
||||
* @return If the operation is successful cbBSE_OK is returned.
|
||||
*/
|
||||
extern cb_int32 cbBSE_open(
|
||||
cbBCM_Handle handle,
|
||||
cbBSE_Callback *pCallback);
|
||||
|
||||
/**
|
||||
* Send data to remote device. A data confirmation event is generated when
|
||||
* the data has been sent and a cbBSE_write call can be done.
|
||||
*
|
||||
* Detailed description optionally verbose.
|
||||
* @param handle Connection handle
|
||||
* @param pBuf Data pointer
|
||||
* @param nBytes nBytes Size of data to be sent.
|
||||
* @param tag Tag passed as argument in corresponding data confirmation callback.
|
||||
* @return If the operation is successful cbBSE_OK is returned.
|
||||
*/
|
||||
extern cb_int32 cbBSE_write(
|
||||
cbBCM_Handle handle,
|
||||
cb_uint8 *pBuf,
|
||||
cb_uint32 nBytes,
|
||||
cb_int32 tag);
|
||||
|
||||
/**
|
||||
* Get received data.
|
||||
*
|
||||
* @param handle Connection handle
|
||||
* @param ppBuf Pointer to data buffer
|
||||
* @param pLength Pointer to buffer length variable.
|
||||
* @return cbBSE_OK is returned if data is available. If no data is available
|
||||
* then cbBSE_NO_DATA is returned.
|
||||
*/
|
||||
extern cb_int32 cbBSE_getReadBuf(
|
||||
cbBCM_Handle handle,
|
||||
cb_uint8 **ppBuf,
|
||||
cb_uint32 *pLength);
|
||||
|
||||
/**
|
||||
* Notify that received data has been handled and underlying buffers
|
||||
* can be freed.
|
||||
*
|
||||
* @param handle Connection handle
|
||||
* @param nBytes Number of bytes consumed.
|
||||
* @return If the operation is successful cbBSE_OK is returned.
|
||||
*/
|
||||
extern cb_int32 cbBSE_readBufConsumed(
|
||||
cbBCM_Handle handle,
|
||||
cb_uint32 nBytes);
|
||||
|
||||
/**
|
||||
* Read max frame size for a data channel.
|
||||
*
|
||||
* @param handle Connection handle
|
||||
* @param pFrameSize Max frame size for connection.
|
||||
* @return If the operation is successful cbBSE_OK is returned.
|
||||
*/
|
||||
extern cb_int32 cbBSE_frameSize(cbBCM_Handle handle, cb_uint32 *pFrameSize);
|
||||
|
||||
/**
|
||||
* Bluetooth serial message handling. Shall not be called by application.
|
||||
*
|
||||
* @param msgId Message id
|
||||
* @param pData Pointer to message data
|
||||
* @return None
|
||||
*/
|
||||
extern void cbBSE_handleMsg(cb_uint32 msgId, void* pData);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -0,0 +1,153 @@
|
|||
/**
|
||||
*---------------------------------------------------------------------------
|
||||
* Copyright (c) 2016, u-blox Malmö, All Rights Reserved
|
||||
* SPDX-License-Identifier: LicenseRef-PBL
|
||||
*
|
||||
* This file and the related binary are licensed under the
|
||||
* Permissive Binary License, Version 1.0 (the "License");
|
||||
* you may not use these files except in compliance with the License.
|
||||
*
|
||||
* You may obtain a copy of the License here:
|
||||
* LICENSE-permissive-binary-license-1.0.txt and at
|
||||
* https://www.mbed.com/licenses/PBL-1.0
|
||||
*
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* Component : Bluetooth Serial
|
||||
* File : cb_bt_serial_le.h
|
||||
*
|
||||
* Description : Data management for Serial Port Service.
|
||||
*
|
||||
*-------------------------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
* @file cb_bt_serial_le.h
|
||||
* @brief Data management for Serial Port Service.
|
||||
*/
|
||||
|
||||
#ifndef _CB_BT_SERIAL_LE_H_
|
||||
#define _CB_BT_SERIAL_LE_H_
|
||||
|
||||
#include "cb_comdefs.h"
|
||||
#include "bt_types.h"
|
||||
#include "cb_bt_conn_man.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*===========================================================================
|
||||
* DEFINES
|
||||
*=========================================================================*/
|
||||
#define cbBSL_OK 0
|
||||
#define cbBSL_ERROR -1
|
||||
#define cbBSL_NO_DATA -2
|
||||
|
||||
/*===========================================================================
|
||||
* TYPES
|
||||
*=========================================================================*/
|
||||
|
||||
typedef void (*cbBSL_DataAvailEvt)(
|
||||
cbBCM_Handle handle);
|
||||
|
||||
typedef void (*cbBSL_WriteCnf)(
|
||||
cbBCM_Handle handle,
|
||||
cb_int32 status,
|
||||
cb_uint32 nBytes,
|
||||
cb_int32 tag);
|
||||
|
||||
typedef struct
|
||||
{
|
||||
cbBSL_DataAvailEvt pfDataEvt;
|
||||
cbBSL_WriteCnf pfWriteCnf;
|
||||
}cbBSL_Callback;
|
||||
|
||||
/*===========================================================================
|
||||
* FUNCTIONS
|
||||
*=========================================================================*/
|
||||
/**
|
||||
* Initialization of Bluetooth serial manager. Called during stack
|
||||
* initialization. Shall not be called by application.
|
||||
*
|
||||
* @return None
|
||||
*/
|
||||
extern void cbBSL_init(void);
|
||||
|
||||
/**
|
||||
* Open a data channel.
|
||||
*
|
||||
* @param handle Connection handle
|
||||
* @param pCallback Callback for data events.
|
||||
* @return If the operation is successful cbBSL_OK is returned.
|
||||
*/
|
||||
extern cb_int32 cbBSL_open(
|
||||
cbBCM_Handle handle,
|
||||
cbBSL_Callback *pCallback);
|
||||
|
||||
/**
|
||||
* Send data to remote device. A data confirmation event is generated when
|
||||
* the data has been sent and a cbBSL_write call can be done.
|
||||
*
|
||||
* Detailed description optionally verbose.
|
||||
* @param handle Connection handle
|
||||
* @param pBuf Data pointer
|
||||
* @param nBytes nBytes Size of data to be sent.
|
||||
* @param tag Tag passed as argument in corresponding data confirmation callback.
|
||||
* @return If the operation is successful cbBSL_OK is returned.
|
||||
*/
|
||||
extern cb_int32 cbBSL_write(
|
||||
cbBCM_Handle handle,
|
||||
cb_uint8 *pBuf,
|
||||
cb_uint32 nBytes,
|
||||
cb_int32 tag);
|
||||
|
||||
/**
|
||||
* Get received data.
|
||||
*
|
||||
* @param handle Connection handle
|
||||
* @param ppBuf Pointer to data buffer
|
||||
* @param pLength Pointer to buffer length variable.
|
||||
* @return cbBSL_OK is returned if data is available. If no data is available
|
||||
* then cbBSL_NO_DATA is returned.
|
||||
*/
|
||||
extern cb_int32 cbBSL_getReadBuf(
|
||||
cbBCM_Handle handle,
|
||||
cb_uint8 **ppBuf,
|
||||
cb_uint32 *pLength);
|
||||
|
||||
/**
|
||||
* Notify that received data has been handled and underlying buffers
|
||||
* can be freed.
|
||||
*
|
||||
* @param handle Connection handle
|
||||
* @param nBytes Number of bytes consumed.
|
||||
* @return If the operation is successful cbBSL_OK is returned.
|
||||
*/
|
||||
extern cb_int32 cbBSL_readBufConsumed(
|
||||
cbBCM_Handle handle,
|
||||
cb_uint32 nBytes);
|
||||
|
||||
/**
|
||||
* Read max frame size for a data channel.
|
||||
*
|
||||
* @param handle Connection handle
|
||||
* @param pFrameSize Max frame size for connection.
|
||||
* @return If the operation is successful cbBSE_OK is returned.
|
||||
*/
|
||||
extern cb_int32 cbBSL_frameSize(cbBCM_Handle handle, cb_uint32 *pFrameSize);
|
||||
|
||||
/**
|
||||
* Bluetooth serial message handling. Shall not be called by application.
|
||||
*
|
||||
* @param msgId Message id
|
||||
* @param pData Pointer to message data
|
||||
* @return None
|
||||
*/
|
||||
extern void cbBSL_handleMsg(cb_uint32 msgId, void* pData);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -0,0 +1,253 @@
|
|||
/*---------------------------------------------------------------------------
|
||||
* Copyright (c) 2016, u-blox Malmö, All Rights Reserved
|
||||
* SPDX-License-Identifier: LicenseRef-PBL
|
||||
*
|
||||
* This file and the related binary are licensed under the
|
||||
* Permissive Binary License, Version 1.0 (the "License");
|
||||
* you may not use these files except in compliance with the License.
|
||||
*
|
||||
* You may obtain a copy of the License here:
|
||||
* LICENSE-permissive-binary-license-1.0.txt and at
|
||||
* https://www.mbed.com/licenses/PBL-1.0
|
||||
*
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* Component : Bluetooth Test
|
||||
* File : cb_bt_test_man.h
|
||||
*
|
||||
* Description : Functionality for Bluetooth radio tests and qualification.
|
||||
*-------------------------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
* @file cb_bt_test_man.h
|
||||
* @brief Functionality for Bluetooth radio tests and qualification.
|
||||
*/
|
||||
|
||||
#ifndef _CB_BT_TEST_MAN_H_
|
||||
#define _CB_BT_TEST_MAN_H_
|
||||
|
||||
#include "cb_comdefs.h"
|
||||
|
||||
#include "cb_bt_man.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*===========================================================================
|
||||
* DEFINES
|
||||
*=========================================================================*/
|
||||
#define cbBTM_OK (0)
|
||||
#define cbBTM_ERROR (-1)
|
||||
|
||||
/*===========================================================================
|
||||
* TYPES
|
||||
*=========================================================================*/
|
||||
typedef enum
|
||||
{
|
||||
cbBTM_TEST_CONF_POS,
|
||||
cbBTM_TEST_CONF_NEG
|
||||
} cbBTM_TestEvt;
|
||||
|
||||
typedef void (*cbBTM_TestCallback)(cbBTM_TestEvt evt);
|
||||
typedef void (*cbBTM_LeTestEndCallback)(cbBTM_TestEvt evt, cb_uint16 nbrOfPackets);
|
||||
|
||||
|
||||
/*===========================================================================
|
||||
* FUNCTIONS
|
||||
*=========================================================================*/
|
||||
|
||||
/**
|
||||
* Init Bluetooth test manager
|
||||
* @returns None
|
||||
*/
|
||||
extern void cbBTM_init(void);
|
||||
|
||||
/**
|
||||
* Enable Device under test mode. Used for Bluetooth Classic radio tests.
|
||||
*
|
||||
* @param callback Test callback used to notify if the test was successfully started.
|
||||
* @returns cbBTM_OK is returned
|
||||
*/
|
||||
extern cb_int32 cbBTM_enableDUT(cbBTM_TestCallback callback);
|
||||
|
||||
/**
|
||||
* This command operates the RF transceiver in continuous transmission mode (which is most likely used in
|
||||
* regulatory and standardization procedures and tests, such as FCC and ETSI certifications). Activating the
|
||||
* VS runs the TX START sequence code using the configured frequency, modulation, pattern, and power
|
||||
* level. The VS also enables the generation of a user-defined pattern (or correcting definitions without a
|
||||
* patch) by setting a new pattern generator (also known as a PN generator) init value and mask.
|
||||
* based on HCI_VS_DRPb_Tester_Con_TX, HCI Opcode 0xFDCA
|
||||
* The cbBTM_TestCallback is used to notify if the test is sucessfully started.
|
||||
*
|
||||
* @param frequency Transmission frequency in MHz Range: 2402 - 2480
|
||||
* @param modulationScheme Range: 0x00 - 0x05 where
|
||||
* 0x00 = CW
|
||||
* 0x01 = BT BR (GFSK)
|
||||
* 0x02 = BT EDR 2MB (p/4-DQPSK)
|
||||
* 0x03 = BT EDR 3MB (8-DPSK)
|
||||
* 0x04 = BT LE (BLE, GMSK)
|
||||
* 0x05 = ANT (GFSK)
|
||||
* @param testPattern Range: 0x00 - 0x07
|
||||
* 0x00 = PN9
|
||||
* 0x01 = PN15
|
||||
* 0x02 = ZOZO (101010101010101010)
|
||||
* 0x03 = All 1
|
||||
* 0x04 = All 0
|
||||
* 0x05 = FOFO (1111000011110000)
|
||||
* 0x06 = FFOO (1111111100000000)
|
||||
* 0x07 = Not used
|
||||
* @param powerLevelIndex Range: 0-7: 7 = Max Output Power, 0 = Min Output Power, 0x08 (PA off) 8 = PA Off (leakage)
|
||||
* @param reserved1 shall be set to 0
|
||||
* @param reserved2 shall be set to 0
|
||||
* @param callback Test callback used to notify if the test was successfully started.
|
||||
*
|
||||
* @return cbBTM_OK is returned
|
||||
*/
|
||||
extern cb_int32 cbBTM_tiDrpbTesterConTx(
|
||||
cb_uint16 frequency,
|
||||
cb_uint8 modulationScheme,
|
||||
cb_uint8 testPattern,
|
||||
cb_uint8 powerLevelIndex,
|
||||
cb_uint32 reserved1,
|
||||
cb_uint32 reserved2,
|
||||
cbBTM_TestCallback callback);
|
||||
|
||||
/**
|
||||
*This command operates the RF transceiver in continuous reception mode (most likely used in regulatory
|
||||
* and standardization procedures and tests, such as FCC and ETSI certifications). By activating the VS, the
|
||||
* RX START sequence code runs, using the configured frequency, RX mode, and modulation type.
|
||||
* based on HCI_VS_DRPb_Tester_Con_RX, HCI Opcode 0xFDCB
|
||||
*
|
||||
* The cbBTM_TestCallback is used to notify if the test is successfully started.
|
||||
* @param frequency Transmission frequency in MHz Range: 2402 - 2480
|
||||
* @param rxMode Range: 0 -3:
|
||||
* 0x00 = Connection mode
|
||||
* 0x01 = Best RF mode (ADPL closed loop) - For expert use only!
|
||||
* 0x02 = Low current mode (ADPLL open loop) - For expert use only!
|
||||
* 0x03 = Scan mode
|
||||
* @param modulationScheme Range: 0x03 - 0x05 where
|
||||
* 0x03 = BT (BR, EDR 2MB, EDR 3MB)
|
||||
* 0x04 = BT LE (BLE, GMSK)
|
||||
* 0x05 = ANT (GFSK)
|
||||
* @param callback Test callback used to notify if the test was successfully started.
|
||||
*
|
||||
* @return cbBTM_OK is returned
|
||||
*/
|
||||
extern cb_int32 cbBTM_tiDrpbTesterConRx(
|
||||
cb_uint16 frequency,
|
||||
cb_uint8 rxMode,
|
||||
cb_uint8 modulationScheme,
|
||||
cbBTM_TestCallback callback);
|
||||
|
||||
/**
|
||||
*
|
||||
* This command operates the RF transceiver in continuous reception mode (most likely used in regulatory
|
||||
* and standardization procedures and tests, such as FCC and ETSI certifications). Activating the VS runs
|
||||
* the RX START sequence code using the configured frequency, RX mode, and modulation type.
|
||||
* This command emulates Bluetooth connection mode. Connection does not require a setup procedure.
|
||||
* Based on HCI_VS_DRPb_Tester_Packet_TX_RX HCI Opcode 0xFDCC
|
||||
*
|
||||
* @param aclPacketType ACL TX packet type. Range: 0x00 - 0x0B
|
||||
* 0x00 = DM1
|
||||
* 0x01 = DH1
|
||||
* 0x02 = DM3
|
||||
* 0x03 = DH3
|
||||
* 0x04 = DM5
|
||||
* 0x05 = DH5
|
||||
* 0x06 = 2-DH1
|
||||
* 0x07 = 2-DH3
|
||||
* 0x08 = 2-DH5
|
||||
* 0x09 = 3-DH1
|
||||
* 0x0A = 3-DH3
|
||||
* 0x0B = 3-DH5
|
||||
* @param frequencyMode 0x00 = Hopping 0x03 = Single frequency
|
||||
* @param txSingleFrequency Transmission frequency in MHz,Range 2402 - 2480, 0xFFFF = no TX
|
||||
* @param rxSingleFrequency Transmission frequency in MHz,Range 2402 - 2480, 0xFFFF = no RX
|
||||
* @param aclDataPattern ACL TX packet data pattern Range: 0x00 - 0x05
|
||||
* 0x00 = All 0
|
||||
* 0x01 = All 1
|
||||
* 0x02 = ZOZO (101010101010101010)
|
||||
* 0x03 = FOFO (1111000011110000)
|
||||
* 0x04 = Ordered (1, 2, 3, 4, and so on)
|
||||
* 0x05 = PRBS9 (pseudo-random bit sequence)
|
||||
* @param useExtendedFeatures Shall be SET to 0
|
||||
* @param aclDataLength ACL packet data length.
|
||||
* DM1: 0 - 17 ACL packet data length in bytes
|
||||
* DH1: 0 - 27
|
||||
* DM3: 0 - 121
|
||||
* DH3: 0 - 183
|
||||
* DM5: 0 - 224
|
||||
* DH5: 0 - 339
|
||||
* 2-DH1: 0 - 54
|
||||
* 2-DH3: 0 - 367
|
||||
* 2-DH5: 0 - 679
|
||||
* 3-DH1: 0 - 83
|
||||
* 3-DH3: 0 - 552
|
||||
* 3-DH5: 0 - 1021
|
||||
* @param powerLevel Range 0-7: 7 = Max Output Power; 0 = Min Output; Power 8 = PA Off (leakage) 0x08 (PA off)
|
||||
* @param disableWhitening 0x00 = Enable whitening, 0x01 = Disable whitening
|
||||
* @param prbs9Init PRBS9 Init, range 0x0000 - 0x01FF
|
||||
* @param callback Test callback used to notify if the test was successfully started.
|
||||
*
|
||||
* @return cbBTM_OK is returned
|
||||
*/
|
||||
extern cb_int32 cbBTM_tiDrpbTesterPacketTxRx(
|
||||
cb_uint8 aclPacketType,
|
||||
cb_uint8 frequencyMode,
|
||||
cb_uint16 txSingleFrequency,
|
||||
cb_uint16 rxSingleFrequency,
|
||||
cb_uint8 aclDataPattern,
|
||||
cb_uint8 useExtendedFeatures,
|
||||
cb_uint16 aclDataLength,
|
||||
cb_uint8 powerLevel,
|
||||
cb_uint8 disableWhitening,
|
||||
cb_uint16 prbs9Init,
|
||||
cbBTM_TestCallback callback);
|
||||
|
||||
/**
|
||||
* Enable Bluetooth Low Energy Transmitter test.
|
||||
* @param txFreq Transmit frequency. N = (F - 2402) / 2, Range: 0x00 to 0x27, Frequency Range : 2402 MHz to 2480 MHz,
|
||||
Use oxFF to generate a pseudo random hopping frequency useful for some scenarios during type approval.
|
||||
* @param length Length in bytes of payload data in each packet
|
||||
* @param packetPayload 0x00 Pseudo-Random bit sequence 9
|
||||
* 0x01 Pattern of alternating bits 11110000
|
||||
* 0x02 Pattern of alternating bits 10101010
|
||||
* 0x03 Pseudo-Random bit sequence 15
|
||||
* 0x04 Pattern of All 1 bits
|
||||
* 0x05 Pattern of All 0 bits
|
||||
* 0x06 Pattern of alternating bits 00001111
|
||||
* 0x07 Pattern of alternating bits 0101
|
||||
* @param callback Test callback used to notify if the test was successfully started.
|
||||
* @return cbBTM_OK is returned
|
||||
*/
|
||||
extern cb_int32 cbBTM_enableBleTransmitterTest(
|
||||
cb_uint8 txFreq,
|
||||
cb_uint8 length,
|
||||
cb_uint8 packetPayload,
|
||||
cbBTM_TestCallback callback);
|
||||
|
||||
/**
|
||||
* Enable Bluetooth Low Energy Receiver test.
|
||||
* @param rxFreq Receive frequency. N = (F - 2402) / 2, Range: 0x00 to 0x27, Frequency Range : 2402 MHz to 2480 MHz,
|
||||
* @param callback Test callback used to notify if the test was successfully started.
|
||||
* @returns cbBTM_OK is returned
|
||||
*/
|
||||
extern cb_int32 cbBTM_enableBleReceiverTest(
|
||||
cb_uint8 rxFreq,
|
||||
cbBTM_TestCallback callback);
|
||||
|
||||
/**
|
||||
* End Bluetooth Low Energy Receiver or Transmitter test.
|
||||
* @param callback Test callback used to notify if the test was successfully ended.
|
||||
* @returns cbBTM_OK is returned
|
||||
*/
|
||||
extern cb_int32 cbBTM_bleTestEnd(cbBTM_LeTestEndCallback callback);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _CB_BT_TEST_MAN_H_ */
|
||||
|
|
@ -0,0 +1,86 @@
|
|||
/*---------------------------------------------------------------------------
|
||||
* Copyright (c) 2016, u-blox Malmö, All Rights Reserved
|
||||
* SPDX-License-Identifier: LicenseRef-PBL
|
||||
*
|
||||
* This file and the related binary are licensed under the
|
||||
* Permissive Binary License, Version 1.0 (the "License");
|
||||
* you may not use these files except in compliance with the License.
|
||||
*
|
||||
* You may obtain a copy of the License here:
|
||||
* LICENSE-permissive-binary-license-1.0.txt and at
|
||||
* https://www.mbed.com/licenses/PBL-1.0
|
||||
*
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* Component : Bluetooth utility
|
||||
* File : cb_bt_utils.h
|
||||
*
|
||||
* Description :
|
||||
*-------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef _CB_BT_UTILS_H_
|
||||
#define _CB_BT_UTILS_H_
|
||||
|
||||
#include "cb_comdefs.h"
|
||||
#include "bt_types.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*===========================================================================
|
||||
* FUNCTIONS
|
||||
*=========================================================================
|
||||
*/
|
||||
|
||||
/**
|
||||
* Compare two Bluetooth addresses
|
||||
*
|
||||
* @param addr1 Pointer to first address to compare
|
||||
* @param addr2 Pointer to second address to compare
|
||||
* @returns TRUE if equal otherwise FALSE
|
||||
*/
|
||||
extern cb_boolean cbBT_UTILS_cmpBdAddr(
|
||||
TBdAddr* addr1,
|
||||
TBdAddr* addr2);
|
||||
|
||||
/**
|
||||
* Check if address in invalid i.e. {{0,0,0,0,0,0},BT_PUBLIC_ADDRESS}
|
||||
*
|
||||
* @param addr Pointer to address to check
|
||||
* @returns TRUE if invalid otherwise FALSE
|
||||
*/
|
||||
extern cb_boolean cbBT_UTILS_isInvalidBdAddr(
|
||||
TBdAddr* addr);
|
||||
|
||||
/**
|
||||
* Set invalid address i.e. {{0,0,0,0,0,0},BT_PUBLIC_ADDRESS}
|
||||
*
|
||||
* @param addr Pointer where to put the address
|
||||
*/
|
||||
extern void cbBT_UTILS_setInvalidBdAddr(
|
||||
TBdAddr* addr);
|
||||
|
||||
/**
|
||||
* Get invalid address
|
||||
*
|
||||
* @returns Pointer to the invalid address
|
||||
*/
|
||||
extern const TBdAddr* cbBT_UTILS_getInvalidBdAddr(void);
|
||||
|
||||
/**
|
||||
* Copy Bluetooth address
|
||||
*
|
||||
* @param dest Pointer to destination address
|
||||
* @param src Pointer to source address
|
||||
*/
|
||||
extern void cbBT_UTILS_cpyBdAddr(
|
||||
TBdAddr* dest,
|
||||
TBdAddr* src);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _CB_BT_UTILS_H_ */
|
|
@ -0,0 +1,178 @@
|
|||
/*---------------------------------------------------------------------------
|
||||
* Copyright (c) 2016, u-blox Malmö, All Rights Reserved
|
||||
* SPDX-License-Identifier: LicenseRef-PBL
|
||||
*
|
||||
* This file and the related binary are licensed under the
|
||||
* Permissive Binary License, Version 1.0 (the "License");
|
||||
* you may not use these files except in compliance with the License.
|
||||
*
|
||||
* You may obtain a copy of the License here:
|
||||
* LICENSE-permissive-binary-license-1.0.txt and at
|
||||
* https://www.mbed.com/licenses/PBL-1.0
|
||||
*
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* Component : Common Definitions
|
||||
* File : cb_comdefs.h
|
||||
*
|
||||
* Description : Common definitions.
|
||||
*-------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef _CB_COMDEFS_H_
|
||||
#define _CB_COMDEFS_H_
|
||||
|
||||
#include "cb_platform_basic_types.h"
|
||||
|
||||
/*===========================================================================
|
||||
* DEFINES
|
||||
*=========================================================================*/
|
||||
|
||||
#ifndef FALSE
|
||||
# define FALSE (0)
|
||||
#endif
|
||||
|
||||
#ifndef TRUE
|
||||
# define TRUE (!FALSE)
|
||||
#endif
|
||||
|
||||
#ifndef NULL
|
||||
# define NULL ((void*)0)
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Returns the maximum value of the two parameters.
|
||||
*/
|
||||
#define cb_MAX(a,b) (((a) > (b)) ? (a) : (b))
|
||||
|
||||
/**
|
||||
* Returns the minimum value of the two parameters.
|
||||
*/
|
||||
#define cb_MIN(a,b) (((a) < (b)) ? (a) : (b))
|
||||
|
||||
/**
|
||||
* Used in function definitions to declare an input parameter unused to avoid warnings.
|
||||
*/
|
||||
#ifndef cb_UNUSED
|
||||
# define cb_UNUSED(x) x
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef cb_ASSERT
|
||||
# error "No platform definition for ASSERT!"
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Used when declaring an empty array that does not take up space in a struct.
|
||||
* Example: struct { cb_uint8 payload[cb_EMPTY_ARRAY]; }
|
||||
* In some compilers this is empty i.e. payload[]. While in some it requires a zero.
|
||||
* I.e. payload[0];
|
||||
* Use this define to get it working for your system.
|
||||
*/
|
||||
#ifndef cb_EMPTY_ARRAY
|
||||
# define cb_EMPTY_ARRAY (0)
|
||||
#endif
|
||||
|
||||
|
||||
#define cb_BIT_0 (1ul)
|
||||
#define cb_BIT_1 (1ul << 1)
|
||||
#define cb_BIT_2 (1ul << 2)
|
||||
#define cb_BIT_3 (1ul << 3)
|
||||
#define cb_BIT_4 (1ul << 4)
|
||||
#define cb_BIT_5 (1ul << 5)
|
||||
#define cb_BIT_6 (1ul << 6)
|
||||
#define cb_BIT_7 (1ul << 7)
|
||||
#define cb_BIT_8 (1ul << 8)
|
||||
#define cb_BIT_9 (1ul << 9)
|
||||
#define cb_BIT_10 (1ul << 10)
|
||||
#define cb_BIT_11 (1ul << 11)
|
||||
#define cb_BIT_12 (1ul << 12)
|
||||
#define cb_BIT_13 (1ul << 13)
|
||||
#define cb_BIT_14 (1ul << 14)
|
||||
#define cb_BIT_15 (1ul << 15)
|
||||
#define cb_BIT_16 (1ul << 16)
|
||||
#define cb_BIT_17 (1ul << 17)
|
||||
#define cb_BIT_18 (1ul << 18)
|
||||
#define cb_BIT_19 (1ul << 19)
|
||||
#define cb_BIT_20 (1ul << 20)
|
||||
#define cb_BIT_21 (1ul << 21)
|
||||
#define cb_BIT_22 (1ul << 22)
|
||||
#define cb_BIT_23 (1ul << 23)
|
||||
#define cb_BIT_24 (1ul << 24)
|
||||
#define cb_BIT_25 (1ul << 25)
|
||||
#define cb_BIT_26 (1ul << 26)
|
||||
#define cb_BIT_27 (1ul << 27)
|
||||
#define cb_BIT_28 (1ul << 28)
|
||||
#define cb_BIT_29 (1ul << 29)
|
||||
#define cb_BIT_30 (1ul << 30)
|
||||
#define cb_BIT_31 (1ul << 31)
|
||||
|
||||
/**
|
||||
* Clears (set to zero) a bit or bits in a variable.
|
||||
* @param variable The variable.
|
||||
* @param bit The bit or bits to clear
|
||||
*/
|
||||
#define cb_CLEAR_BIT(variable,bit) ((variable) &= ~((bit)))
|
||||
|
||||
/**
|
||||
* Gets a bit i.e. checks if it is set in a variable.
|
||||
*
|
||||
* Also works to see if any of several bits are set.
|
||||
*
|
||||
* @param variable The variable.
|
||||
* @param bit The bit to check if it set.
|
||||
* @return @ref TRUE if any of the bits are set, @ref FALSE otherwise.
|
||||
*/
|
||||
#define cb_GET_BIT(variable,bit) (((variable) & ((bit))) ? TRUE : FALSE)
|
||||
|
||||
/**
|
||||
* Calculate the number of elements in an array.
|
||||
*
|
||||
* @note Won't work on pointer to array as the sizeof(pointer) is 4.
|
||||
*
|
||||
* @param _array The array.
|
||||
* @return Number of elements in array.
|
||||
*/
|
||||
#define ELEMENTS_OF(_array) (sizeof((_array)) / sizeof((_array)[0]))
|
||||
|
||||
/**
|
||||
* Sets (set to 1) a bit or bits in a variable.
|
||||
*
|
||||
* @param variable The variable.
|
||||
* @param bit The bit or bits to set in the variable.
|
||||
*/
|
||||
#define cb_SET_BIT(variable,bit) ((variable) |= (bit))
|
||||
|
||||
#define cb_UINT8_MAX ((cb_uint8)0xff)
|
||||
#define cb_UINT16_MAX ((cb_uint16)0xffff)
|
||||
#define cb_UINT32_MAX ((cb_uint32)0xffffffff)
|
||||
#define cb_INT8_MAX ((cb_int8)0x7f)
|
||||
#define cb_INT16_MAX ((cb_int16)0x7fff)
|
||||
#define cb_INT32_MAX ((cb_int32)0x7fffffff)
|
||||
#define cb_INT8_MIN ((cb_int8)0x80)
|
||||
#define cb_INT16_MIN ((cb_int16)0x8000)
|
||||
#define cb_INT32_MIN ((cb_int32)0x80000000)
|
||||
|
||||
|
||||
|
||||
#define cb_PACKED_STRUCT_BEGIN(name) \
|
||||
cb_PACKED_STRUCT_ATTR_PRE \
|
||||
typedef cb_PACKED_STRUCT_ATTR_INLINE_PRE struct name##_t
|
||||
|
||||
#define cb_PACKED_STRUCT_END(name) \
|
||||
cb_PACKED_STRUCT_ATTR_INLINE_POST name; \
|
||||
cb_PACKED_STRUCT_ATTR_POST
|
||||
|
||||
#ifdef __GNUC__
|
||||
# define DO_PRAGMA(x) _Pragma (#x)
|
||||
# define TODO(x) DO_PRAGMA(message ("TODO - " #x))
|
||||
#else
|
||||
# define TODO(x)
|
||||
#endif
|
||||
|
||||
/*===========================================================================
|
||||
* TYPES
|
||||
*=========================================================================*/
|
||||
|
||||
#endif /* _cb_COMDEFS_H_ */
|
||||
|
|
@ -0,0 +1,504 @@
|
|||
/*
|
||||
*---------------------------------------------------------------------------
|
||||
* Copyright (c) 2016, u-blox Malmö, All Rights Reserved
|
||||
* SPDX-License-Identifier: LicenseRef-PBL
|
||||
*
|
||||
* This file and the related binary are licensed under the
|
||||
* Permissive Binary License, Version 1.0 (the "License");
|
||||
* you may not use these files except in compliance with the License.
|
||||
*
|
||||
* You may obtain a copy of the License here:
|
||||
* LICENSE-permissive-binary-license-1.0.txt and at
|
||||
* https://www.mbed.com/licenses/PBL-1.0
|
||||
*
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* Component : GATT
|
||||
* File : cb_gatt.h
|
||||
*
|
||||
* Description : Definitions and types for GATT(Generic Attribute Profile)
|
||||
* that are in common for both client and server.
|
||||
*
|
||||
*-------------------------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
* @file cb_gatt.h
|
||||
*
|
||||
* @brief Definitions and types for GATT(Generic Attribute Profile)
|
||||
* that are in common for both client and server.
|
||||
*/
|
||||
|
||||
#ifndef _CB_GATT_H_
|
||||
#define _CB_GATT_H_
|
||||
|
||||
#include "bt_types.h"
|
||||
|
||||
/*===========================================================================
|
||||
* DEFINES
|
||||
*=========================================================================*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define cbGATT_OK (0)
|
||||
#define cbGATT_ERROR (-1)
|
||||
#define cbGATT_ERROR_WRONG_STATE (-2)
|
||||
#define cbGATT_ERROR_WRONG_HANDLE (-3)
|
||||
#define cbGATT_ERROR_WRONG_PARAMETERS (-4)
|
||||
|
||||
// This should be the same as in ATT
|
||||
#define cbGATT_DEFAULT_MTU_LE 23
|
||||
|
||||
#define cbGATT_GET_MAX_READ_MULTIPLE_MTU(mtu) (mtu-1)
|
||||
#define cbGATT_GET_MAX_WRITE_CHARACTERISTIC_MTU(mtu) (mtu-3)
|
||||
#define cbGATT_GET_MAX_WRITE_SIGNED_CHARACTERISTIC_MTU(mtu) (mtu-13)
|
||||
#define cbGATT_GET_MAX_NOTIFICATION_MTU(mtu) (mtu-3)
|
||||
#define cbGATT_GET_MAX_INDICATION_MTU(mtu) (mtu-3)
|
||||
|
||||
#define cbGATT_INVALID_ATTR_HANDLE 0x0000
|
||||
#define cbGATT_MIN_ATTR_HANDLE 0x0001
|
||||
#define cbGATT_MAX_ATTR_HANDLE 0xFFFF
|
||||
|
||||
#define cbGATT_PROP_BCST 0x01 // Broadcast
|
||||
#define cbGATT_PROP_RD 0x02 // Readable
|
||||
#define cbGATT_PROP_WR_NO_RSP 0x04 // Write with no response
|
||||
#define cbGATT_PROP_WR 0x08 // Writable
|
||||
#define cbGATT_PROP_NOT 0x10 // Notify
|
||||
#define cbGATT_PROP_IND 0x20 // Indicate
|
||||
#define cbGATT_PROP_SIGN_WR 0x40 // Authenticated signed write
|
||||
#define cbGATT_PROP_EXT 0x80 // extended property
|
||||
|
||||
#define cbGATT_PROP_EXT_REL_WR 0x0001 // Reliable write
|
||||
#define cbGATT_PROP_EXT_WR_AUX 0x0002 // auxiliary write
|
||||
#define cbGATT_CLIENT_CFG_NONE 0x0000 // Client configuration disabled
|
||||
#define cbGATT_CLIENT_CFG_NOT 0x0001 // Client notification configuration
|
||||
#define cbGATT_CLIENT_CFG_IND 0x0002 // Server indication configuration
|
||||
#define cbGATT_SERVER_CFG_BCST 0x0001 // Server broadcast configuration
|
||||
|
||||
#define cbGATT_GET_BROADCAST_PROP(prop) ((0x01 & prop) == 0x01)
|
||||
#define cbGATT_GET_READ_PROP(prop) ((0x02 & prop) == 0x02)
|
||||
#define cbGATT_GET_WRITE_WITHOUT_RSP_PROP(prop) ((0x04 & prop) == 0x04)
|
||||
#define cbGATT_GET_WRITE_PROP(prop) ((0x08 & prop) == 0x08)
|
||||
#define cbGATT_GET_NOTIFY_PROP(prop) ((0x10 & prop) == 0x10)
|
||||
#define cbGATT_GET_INDICATE_PROP(prop) ((0x20 & prop) == 0x20)
|
||||
#define cbGATT_GET_AUTH_SIGNED_WRITES_PROP(prop) ((0x40 & prop) == 0x40)
|
||||
#define cbGATT_GET_EXTENDED_PROP(prop) ((0x80 & prop) == 0x80)
|
||||
|
||||
#define cbGATT_GET_PROP_EXT_REL_WR(prop) ((0x0001 & prop) == 0x0001)
|
||||
#define cbGATT_GET_PROP_EXT_WR_AUX(prop) ((0x0002 & prop) == 0x0002)
|
||||
#define cbGATT_GET_CLIENT_CFG_NOT(cfg) ((0x0001 & cfg) == 0x0001)
|
||||
#define cbGATT_GET_CLIENT_CFG_IND(cfg) ((0x0002 & cfg) == 0x0002)
|
||||
#define cbGATT_GET_SERVER_CFG_BCST(cfg) ((0x0001 & cfg) == 0x0001)
|
||||
|
||||
#define cbGATT_SET_BROADCAST_PROP(prop) (prop = prop | 0x01)
|
||||
#define cbGATT_SET_READ_PROPERTY(prop) (prop = prop | 0x02)
|
||||
#define cbGATT_SET_WRITE_WITHOUT_RSP_PROP(prop) (prop = prop | 0x04)
|
||||
#define cbGATT_SET_WRITE_PROP(prop) (prop = prop | 0x08)
|
||||
#define cbGATT_SET_NOTIFY_PROP(prop) (prop = prop | 0x10)
|
||||
#define cbGATT_SET_INDICATE_PROP(prop) (prop = prop | 0x20)
|
||||
#define cbGATT_SET_AUTH_SIGNED_WRITES_PROP(prop) (prop = prop | 0x40)
|
||||
#define cbGATT_SET_EXTENDED_PROP(prop) (prop = prop | 0x80)
|
||||
|
||||
#define cbGATT_SET_PROP_EXT_REL_WR(prop) (prop = prop | 0x0001)
|
||||
#define cbGATT_SET_PROP_EXT_WR_AUX(prop) (prop = prop | 0x0002)
|
||||
#define cbGATT_SET_CLIENT_CFG_NOT(cfg) (cfg = cfg | 0x0001)
|
||||
#define cbGATT_SET_CLIENT_CFG_IND(cfg) (cfg = cfg | 0x0002)
|
||||
#define cbGATT_SET_SERVER_CFG_BCST(cfg) (cfg = cfg | 0x0001)
|
||||
|
||||
// Below specification level as of 2011-09-13
|
||||
#define cbGATT_SERVICE_GENERIC_ACCESS 0x1800 // 0.5
|
||||
#define cbGATT_SERVICE_GENERIC_ATTRIBUTE 0x1801 // 0.5
|
||||
#define cbGATT_SERVICE_IMMEDIATE_ALERT 0x1802 // Adopted
|
||||
#define cbGATT_SERVICE_LINK_LOSS 0x1803 // Adopted
|
||||
#define cbGATT_SERVICE_TX_POWER 0x1804 // Adopted
|
||||
#define cbGATT_SERVICE_CURRENT_TIME 0x1805 // Prototype
|
||||
#define cbGATT_SERVICE_REFERENCE_TIME_UPDATE 0x1806 // Prototype
|
||||
#define cbGATT_SERVICE_NEXT_DST_CHANGE 0x1807 // Prototype
|
||||
#define cbGATT_SERVICE_HEALTH_THERMOMETER 0x1809 // Adopted
|
||||
#define cbGATT_SERVICE_DEVICE_INFORMATION 0x180A // Adopted
|
||||
#define cbGATT_SERVICE_NETWORK_AVAILABILITY 0x180B // 0.9
|
||||
#define cbGATT_SERVICE_WATCHDOG 0x180C // 0.5
|
||||
#define cbGATT_SERVICE_HEART_RATE 0x180D // Adopted
|
||||
#define cbGATT_SERVICE_PHONE_ALERT_STATUS 0x180E // Prototype
|
||||
#define cbGATT_SERVICE_BATTERY_SERVICE 0x180F // Prototype
|
||||
#define cbGATT_SERVICE_BLOOD_PRESSURE 0x1810 // 0.9
|
||||
#define cbGATT_SERVICE_ALERT_NOTIFICATION 0x1811 // Prototype
|
||||
#define cbGATT_SERVICE_HUMAN_INTERFACE_DEVICE 0x1812 // 0.5
|
||||
#define cbGATT_SERVICE_SCAN_PARAMETER 0x1813 // 0.5
|
||||
|
||||
#define cbGATT_PRIMARY_SERVICE_DECL 0x2800
|
||||
#define cbGATT_SECONDARY_SERVICE_DECL 0x2801
|
||||
#define cbGATT_INCLUDE_DECL 0x2802
|
||||
#define cbGATT_CHAR_DECL 0x2803
|
||||
#define cbGATT_CHAR_EXT_PROP 0x2900
|
||||
#define cbGATT_CHAR_USER_DESC 0x2901
|
||||
#define cbGATT_CLIENT_CHAR_CONFIG 0x2902
|
||||
#define cbGATT_SERVER_CHAR_CONFIG 0x2903
|
||||
#define cbGATT_CHAR_FORMAT 0x2904
|
||||
#define cbGATT_CHAR_AGGR_FORMAT 0x2905
|
||||
|
||||
#define cbGATT_CHAR_GAP_DEVICE_NAME 0x2A00 // Adopted
|
||||
#define cbGATT_CHAR_GAP_APPEARANCE 0x2A01 // Adopted
|
||||
#define cbGATT_CHAR_GAP_PERIP_PRIV 0x2A02 // Adopted
|
||||
#define cbGATT_CHAR_GAP_RECONN_ADDR 0x2A03 // Adopted
|
||||
#define cbGATT_CHAR_GAP_CONN_PARAMS 0x2A04 // Adopted
|
||||
#define cbGATT_CHAR_GATT_SVC_CHANGED 0x2A05 // Adopted
|
||||
#define cbGATT_CHAR_ALERT_LEVEL 0x2A06 // Adopted
|
||||
#define cbGATT_CHAR_TX_POWER_LEVEL 0x2A07 // Adopted
|
||||
#define cbGATT_CHAR_DATE_TIME 0x2A08 // Adopted
|
||||
#define cbGATT_CHAR_DAY_OF_WEEK 0x2A09 // Prototype
|
||||
#define cbGATT_CHAR_DAY_DATE_TIME 0x2A0A // Prototype
|
||||
#define cbGATT_CHAR_EXACT_TIME_100 0x2A0B // 0.9
|
||||
#define cbGATT_CHAR_EXACT_TIME_256 0x2A0C // Prototype
|
||||
#define cbGATT_CHAR_DST_OFFSET 0x2A0D // Prototype
|
||||
#define cbGATT_CHAR_TIME_ZONE 0x2A0E // Prototype
|
||||
#define cbGATT_CHAR_LOCAL_TIME_INFORMATION 0x2A0F // Prototype
|
||||
#define cbGATT_CHAR_SECONDARY_TIME_ZONE 0x2A10 // 0.9
|
||||
#define cbGATT_CHAR_TIME_WITH_DST 0x2A11 // Prototype
|
||||
#define cbGATT_CHAR_TIME_ACCURACY 0x2A12 // Prototype
|
||||
#define cbGATT_CHAR_TIME_SOURCE 0x2A13 // Prototype
|
||||
#define cbGATT_CHAR_REFERENCE_TIME_INFORMATION 0x2A14 // Prototype
|
||||
#define cbGATT_CHAR_TIME_BROADCAST 0x2A15 // 0.9
|
||||
#define cbGATT_CHAR_TIME_UPDATE_CONTROL_POINT 0x2A16 // Prototype
|
||||
#define cbGATT_CHAR_TIME_UPDATE_STATE 0x2A17 // Prototype
|
||||
#define cbGATT_CHAR_BOOLEAN 0x2A18 // 0.9
|
||||
#define cbGATT_CHAR_BATTERY_LEVEL 0x2A19 // 0.9
|
||||
#define cbGATT_CHAR_BATTERY_POWER_STATE 0x2A1A // 0.9
|
||||
#define cbGATT_CHAR_BATTERY_LEVEL_STATE 0x2A1B // 0.9
|
||||
#define cbGATT_CHAR_TEMP_MEASUREMENT 0x2A1C // Adopted
|
||||
#define cbGATT_CHAR_TEMP_TYPE 0x2A1D // Adopted
|
||||
#define cbGATT_CHAR_INTERMEDIATE_TEMP 0x2A1E // Adopted
|
||||
#define cbGATT_CHAR_TEMP_CELSIUS 0x2A1F // 0.9
|
||||
#define cbGATT_CHAR_TEMP_FAHRENHEIT 0x2A20 // 0.9
|
||||
#define cbGATT_CHAR_MEASUREMENT_INTERVAL 0x2A21 // Adopted
|
||||
#define cbGATT_CHAR_SYSTEM_ID 0x2A23 // Adopted
|
||||
#define cbGATT_CHAR_MODEL_NUMBER_STRING 0x2A24 // Adopted
|
||||
#define cbGATT_CHAR_SERIAL_NUMBER_STRING 0x2A25 // Adopted
|
||||
#define cbGATT_CHAR_FIRMWARE_REV_STRING 0x2A26 // Adopted
|
||||
#define cbGATT_CHAR_HARDWARE_REV_STRING 0x2A27 // Adopted
|
||||
#define cbGATT_CHAR_SOFTWARE_REV_STRING 0x2A28 // Adopted
|
||||
#define cbGATT_CHAR_MANUFACTURER_NAME_STRING 0x2A29 // Adopted
|
||||
#define cbGATT_CHAR_IEEE_REG_CERT_DATA_LIST 0x2A2A // Adopted
|
||||
#define cbGATT_CHAR_CURRENT_TIME 0x2A2B // Prototype
|
||||
#define cbGATT_CHAR_ELEVATION 0x2A2C // 0.5
|
||||
#define cbGATT_CHAR_LATITUDE 0x2A2D // 0.5
|
||||
#define cbGATT_CHAR_LONGITUDE 0x2A2E // 0.5
|
||||
#define cbGATT_CHAR_POSITION_2D 0x2A2F // 0.5
|
||||
#define cbGATT_CHAR_POSITION_3D 0x2A30 // 0.5
|
||||
#define cbGATT_CHAR_VENDOR_ID_V1_1 0x2A31 // 0.5
|
||||
#define cbGATT_CHAR_PRODUCT_ID 0x2A32 // 0.5
|
||||
#define cbGATT_CHAR_HID_VERSION 0x2A33 // 0.5
|
||||
#define cbGATT_CHAR_VENDOR_ID_SOURCE 0x2A34 // 0.5
|
||||
#define cbGATT_CHAR_BLOOD_PRESSURE_MEASUREMENT 0x2A35 // 0.9
|
||||
#define cbGATT_CHAR_INTERMEDIATE_BLOOD_PRESSURE 0x2A36 // 0.9
|
||||
#define cbGATT_CHAR_HEART_RATE_MEASUREMENT 0x2A37 // Adopted
|
||||
#define cbGATT_CHAR_BODY_SENSOR_LOCATION 0x2A38 // Adopted
|
||||
#define cbGATT_CHAR_HEART_RATE_CONTROL_POINT 0x2A39 // Adopted
|
||||
#define cbGATT_CHAR_REMOVABLE 0x2A3A // 0.5
|
||||
#define cbGATT_CHAR_SERVICE_REQUIRED 0x2A3B // 0.9
|
||||
#define cbGATT_CHAR_SCIENTIFIC_TEMP_CELSIUS 0x2A3C // 0.9
|
||||
#define cbGATT_CHAR_STRING 0x2A3D // 0.9
|
||||
#define cbGATT_CHAR_NETWORK_AVAILABILITY 0x2A3E // 0.9
|
||||
#define cbGATT_CHAR_ALERT_STATUS 0x2A3F // Prototype
|
||||
#define cbGATT_CHAR_RINGER_CONTROL_POINT 0x2A40 // Prototype
|
||||
#define cbGATT_CHAR_RINGER_SETTING 0x2A41 // Prototype
|
||||
#define cbGATT_CHAR_ALERT_CATEGORY_ID_BIT_MASK 0x2A42 // 0.9
|
||||
#define cbGATT_CHAR_ALERT_CATEGORY_ID 0x2A43 // 0.9
|
||||
#define cbGATT_CHAR_ALERT_NOTIF_CONTROL_POINT 0x2A44 // 0.9
|
||||
#define cbGATT_CHAR_UNREAD_ALERT_STATUS 0x2A45 // 0.9
|
||||
#define cbGATT_CHAR_NEW_ALERT 0x2A46 // 0.9
|
||||
#define cbGATT_CHAR_SUPPORTED_NEW_ALERT_CATEGORY 0x2A47 // 0.9
|
||||
#define cbGATT_CHAR_SUPPORTED_UNREAD_ALERT_CATEGORY 0x2A48 // 0.9
|
||||
#define cbGATT_CHAR_BLOOD_PRESSURE_FEATURE 0x2A49 // 0.9
|
||||
|
||||
/*==============================================================================
|
||||
* TYPES
|
||||
*==============================================================================
|
||||
*/
|
||||
|
||||
typedef enum
|
||||
{
|
||||
cbGATT_WRITE_METHOD_WITH_RSP,
|
||||
cbGATT_WRITE_METHOD_NO_RSP,
|
||||
cbGATT_WRITE_METHOD_SIGN,
|
||||
cbGATT_WRITE_METHOD_RELIABLE_PREPARE,
|
||||
} cbGATT_WriteMethod;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
cbGATT_UNIT_UNITLESS = 0x2700,
|
||||
cbGATT_UNIT_LENGTH_METRE = 0x2701,
|
||||
cbGATT_UNIT_MASS_KILOGRAM = 0x2702,
|
||||
cbGATT_UNIT_TIME_SECOND = 0x2703,
|
||||
cbGATT_UNIT_ELECTRIC_CURRENT_AMPERE = 0x2704,
|
||||
cbGATT_UNIT_THERMODYNAMIC_TEMPERATURE_KELVIN = 0x2705,
|
||||
cbGATT_UNIT_AMOUNT_OF_SUBSTANCE_MOLE = 0x2706,
|
||||
cbGATT_UNIT_LUMINOUS_INTENSITY_CANDELA = 0x2707,
|
||||
cbGATT_UNIT_AREA_SQUARE_METRES = 0x2710,
|
||||
cbGATT_UNIT_VOLUME_CUBIC_METRES = 0x2711,
|
||||
cbGATT_UNIT_VELOCITY_METRES_PER_SECOND = 0x2712,
|
||||
cbGATT_UNIT_ACCELERATION_METRES_PER_SECOND_SQUARED = 0x2713,
|
||||
cbGATT_UNIT_WAVENUMBER_RECIPROCAL_METRE = 0x2714,
|
||||
cbGATT_UNIT_DENSITY_KILOGRAM_PER_CUBIC_METRE = 0x2715,
|
||||
cbGATT_UNIT_SURFACE_DENSITY_KILOGRAM_PER_SQUARE_METRE = 0x2716,
|
||||
cbGATT_UNIT_SPECIFIC_VOLUME_CUBIC_METRE_PER_KILOGRAM = 0x2717,
|
||||
cbGATT_UNIT_CURRENT_DENSITY_AMPERE_PER_SQUARE_METRE = 0x2718,
|
||||
cbGATT_UNIT_MAGNETIC_FIELD_STRENGTH_AMPERE_PER_METRE = 0x2719,
|
||||
cbGATT_UNIT_AMOUNT_CONCENTRATION_MOLE_PER_CUBIC_METRE = 0x271A,
|
||||
cbGATT_UNIT_MASS_CONCENTRATION_KILOGRAM_PER_CUBIC_METRE = 0x271B,
|
||||
cbGATT_UNIT_LUMINANCE_CANDELA_PER_SQUARE_METRE = 0x271C,
|
||||
cbGATT_UNIT_REFRACTIVE_INDEX = 0x271D,
|
||||
cbGATT_UNIT_RELATIVE_PERMEABILITY = 0x271E,
|
||||
cbGATT_UNIT_PLANE_ANGLE_RADIAN = 0x2720,
|
||||
cbGATT_UNIT_SOLID_ANGLE_STERADIAN = 0x2721,
|
||||
cbGATT_UNIT_FREQUENCY_HERTZ = 0x2722,
|
||||
cbGATT_UNIT_FORCE_NEWTON = 0x2723,
|
||||
cbGATT_UNIT_PRESSURE_PASCAL = 0x2724,
|
||||
cbGATT_UNIT_ENERGY_JOULE = 0x2725,
|
||||
cbGATT_UNIT_POWER_WATT = 0x2726,
|
||||
cbGATT_UNIT_ELECTRIC_CHARGE_COULOMB = 0x2727,
|
||||
cbGATT_UNIT_ELECTRIC_POTENTIAL_DIFFERENCE_VOLT = 0x2728,
|
||||
cbGATT_UNIT_CAPACITANCE_FARAD = 0x2729,
|
||||
cbGATT_UNIT_ELECTRIC_RESISTANCE_OHM = 0x272A,
|
||||
cbGATT_UNIT_ELECTRIC_CONDUCTANCE_SIEMENS = 0x272B,
|
||||
cbGATT_UNIT_MAGNETIC_FLEX_WEBER = 0x272C,
|
||||
cbGATT_UNIT_MAGNETIC_FLEX_DENSITY_TESLA = 0x272D,
|
||||
cbGATT_UNIT_INDUCTANCE_HENRY = 0x272E,
|
||||
cbGATT_UNIT_THERMODYNAMIC_TEMPERATURE_DEGREE_CELSIUS = 0x272F,
|
||||
cbGATT_UNIT_LUMINOUS_FLUX_LUMEN = 0x2730,
|
||||
cbGATT_UNIT_ILLUMINANCE_LUX = 0x2731,
|
||||
cbGATT_UNIT_ACTIVITY_REFERRED_TO_A_RADIONUCLIDE_BECQUEREL = 0x2732,
|
||||
cbGATT_UNIT_ABSORBED_DOSE_GRAY = 0x2733,
|
||||
cbGATT_UNIT_DOSE_EQUIVALENT_SIEVERT = 0x2734,
|
||||
cbGATT_UNIT_CATALYTIC_ACTIVITY_KATAL = 0x2735,
|
||||
cbGATT_UNIT_DYNAMIC_VISCOSITY_PASCAL_SECOND = 0x2740,
|
||||
cbGATT_UNIT_MOMENT_OF_FORCE_NEWTON_METRE = 0x2741,
|
||||
cbGATT_UNIT_SURFACE_TENSION_NEWTON_PER_METRE = 0x2742,
|
||||
cbGATT_UNIT_ANGULAR_VELOCITY_RADIAN_PER_SECOND = 0x2743,
|
||||
cbGATT_UNIT_ANGULAR_ACCELERATION_RADIAN_PER_SECOND_SQUARED = 0x2744,
|
||||
cbGATT_UNIT_HEAT_FLUX_DENSITY_WATT_PER_SQUARE_METRE = 0x2745,
|
||||
cbGATT_UNIT_HEAT_CAPACITY_JOULE_PER_KELVIN = 0x2746,
|
||||
cbGATT_UNIT_SPECIFIC_HEAT_CAPACITY_JOULE_PER_KILOGRAM_KELVIN = 0x2747,
|
||||
cbGATT_UNIT_SPECIFIC_ENERGY_JOULE_PER_KILOGRAM = 0x2748,
|
||||
cbGATT_UNIT_THERMAL_CONDUCTIVITY_WATT_PER_METRE_KELVIN = 0x2749,
|
||||
cbGATT_UNIT_ENERGY_DENSITY_JOULE_PER_CUBIC_METRE = 0x274A,
|
||||
cbGATT_UNIT_ELECTRIC_FIELD_STRENGTH_VOLT_PER_METRE = 0x274B,
|
||||
cbGATT_UNIT_ELECTRIC_CHARGE_DENSITY_COULOMB_PER_CUBIC_METRE = 0x274C,
|
||||
cbGATT_UNIT_SURFACE_CHARGE_DENSITY_COULOMB_PER_SQUARE_METRE = 0x274D,
|
||||
cbGATT_UNIT_ELECTRIC_FLUX_DENSITY_COULOMB_PER_SQUARE_METRE = 0x274E,
|
||||
cbGATT_UNIT_PERMITTIVITY_FARAD_PER_METRE = 0x274F,
|
||||
cbGATT_UNIT_PERMEABILITY_HENRY_PER_METRE = 0x2750,
|
||||
cbGATT_UNIT_MOLAR_ENERGY_JOULE_PER_MOLE = 0x2751,
|
||||
cbGATT_UNIT_MOLAR_ENTROPY_JOULE_PER_MOLE_KELVIN = 0x2752,
|
||||
cbGATT_UNIT_EXPOSURE_COULOMB_PER_KILOGRAM = 0x2753,
|
||||
cbGATT_UNIT_ABSORBED_DOSE_RATE_GRAY_PER_SECOND = 0x2754,
|
||||
cbGATT_UNIT_RADIANT_INTENSITY_WATT_PER_STERADIAN = 0x2755,
|
||||
cbGATT_UNIT_RADIANCE_WATT_PER_SQUARE_METER_STERADIAN = 0x2756,
|
||||
cbGATT_UNIT_CATALYTIC_ACTIVITY_CONCENTRATION_KATAL_PER_CUBIC_METRE = 0x2757,
|
||||
cbGATT_UNIT_TIME_MINUTE = 0x2760,
|
||||
cbGATT_UNIT_TIME_HOUR = 0x2761,
|
||||
cbGATT_UNIT_TIME_DAY = 0x2762,
|
||||
cbGATT_UNIT_PLANE_ANGLE_DEGREE = 0x2763,
|
||||
cbGATT_UNIT_PLANE_ANGLE_MINUTE = 0x2764,
|
||||
cbGATT_UNIT_PLANE_ANGLE_SECOND = 0x2765,
|
||||
cbGATT_UNIT_AREA_HECTARE = 0x2766,
|
||||
cbGATT_UNIT_VOLUME_LITRE = 0x2767,
|
||||
cbGATT_UNIT_MASS_TONNE = 0x2768,
|
||||
cbGATT_UNIT_PRESSURE_BAR = 0x2780,
|
||||
cbGATT_UNIT_PRESSURE_MILLIMETRE_OF_MERCURY = 0x2781,
|
||||
cbGATT_UNIT_LENGTH_ANGSTROM = 0x2782,
|
||||
cbGATT_UNIT_LENGTH_NAUTICAL_MILE = 0x2783,
|
||||
cbGATT_UNIT_AREA_BARN = 0x2784,
|
||||
cbGATT_UNIT_VELOCITY_KNOT = 0x2785,
|
||||
cbGATT_UNIT_LOGARITHMIC_RADIO_QUANTITY_NEPER = 0x2786,
|
||||
cbGATT_UNIT_LOGARITHMIC_RADIO_QUANTITY_BEL = 0x2787,
|
||||
cbGATT_UNIT_LENGTH_YARD = 0x27A0,
|
||||
cbGATT_UNIT_LENGTH_PARSEC = 0x27A1,
|
||||
cbGATT_UNIT_LENGTH_INCH = 0x27A2,
|
||||
cbGATT_UNIT_LENGTH_FOOT = 0x27A3,
|
||||
cbGATT_UNIT_LENGTH_MILE = 0x27A4,
|
||||
cbGATT_UNIT_PRESSURE_POUND_FORCE_PER_SQUARE_INCH = 0x27A5,
|
||||
cbGATT_UNIT_VELOCITY_KILOMETRE_PER_HOUR = 0x27A6,
|
||||
cbGATT_UNIT_VELOCITY_MILE_PER_HOUR = 0x27A7,
|
||||
cbGATT_UNIT_ANGULAR_VELOCITY_REVOLUTION_PER_MINUTE = 0x27A8,
|
||||
cbGATT_UNIT_ENERGY_GRAM_CALORIE = 0x27A9,
|
||||
cbGATT_UNIT_ENERGY_KILOGRAM_CALORIE = 0x27AA,
|
||||
cbGATT_UNIT_ENERGY_KILOWATT_HOUR = 0x27AB,
|
||||
cbGATT_UNIT_THERMODYNAMIC_TEMPERATURE_DEGREE_FAHRENHEIT = 0x27AC,
|
||||
cbGATT_UNIT_PERCENTAGE = 0x27AD,
|
||||
cbGATT_UNIT_PER_MILLE = 0x27AE,
|
||||
cbGATT_UNIT_PERIOD_BEATS_PER_MINUTE = 0x27AF,
|
||||
cbGATT_UNIT_ELECTRIC_CHARGE_AMPERE_HOURS = 0x27B0,
|
||||
cbGATT_UNIT_MASS_DENSITY_MILLIGRAM_PER_DECILITRE = 0x27B1,
|
||||
cbGATT_UNIT_MASS_DENSITY_MILLIMOLE_PER_LITRE = 0x27B2,
|
||||
cbGATT_UNIT_TIME_YEAR = 0x27B3,
|
||||
cbGATT_UNIT_TIME_MONTH = 0x27B4,
|
||||
} cbGATT_Unit;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
|
||||
// Note, check http://developer.bluetooth.org/gatt/descriptors/Pages/DescriptorViewer.aspx?u=org.bluetooth.descriptor.cbGATT.characteristic_presentation_format.xml
|
||||
// for any changes
|
||||
cbGATT_FORMAT_TYPE_BOOLEAN = 0x01,
|
||||
cbGATT_FORMAT_TYPE_2BIT = 0x02,
|
||||
cbGATT_FORMAT_TYPE_NIBBLE = 0x03,
|
||||
cbGATT_FORMAT_TYPE_UINT8 = 0x04,
|
||||
cbGATT_FORMAT_TYPE_UINT12 = 0x05,
|
||||
cbGATT_FORMAT_TYPE_UINT16 = 0x06,
|
||||
cbGATT_FORMAT_TYPE_UINT24 = 0x07,
|
||||
cbGATT_FORMAT_TYPE_UINT32 = 0x08,
|
||||
cbGATT_FORMAT_TYPE_UINT48 = 0x09,
|
||||
cbGATT_FORMAT_TYPE_UINT64 = 0x0A,
|
||||
cbGATT_FORMAT_TYPE_UINT128 = 0x0B,
|
||||
cbGATT_FORMAT_TYPE_SINT8 = 0x0C,
|
||||
cbGATT_FORMAT_TYPE_SINT12 = 0x0D,
|
||||
cbGATT_FORMAT_TYPE_SINT16 = 0x0E,
|
||||
cbGATT_FORMAT_TYPE_SINT24 = 0x0F,
|
||||
cbGATT_FORMAT_TYPE_SINT32 = 0x10,
|
||||
cbGATT_FORMAT_TYPE_SINT48 = 0x11,
|
||||
cbGATT_FORMAT_TYPE_SINT64 = 0x12,
|
||||
cbGATT_FORMAT_TYPE_SINT128 = 0x13,
|
||||
cbGATT_FORMAT_TYPE_FLOAT32 = 0x14,
|
||||
cbGATT_FORMAT_TYPE_FLOAT64 = 0x15,
|
||||
cbGATT_FORMAT_TYPE_SFLOAT = 0x16,
|
||||
cbGATT_FORMAT_TYPE_FLOAT = 0x17,
|
||||
cbGATT_FORMAT_TYPE_DUINT16 = 0x18,
|
||||
cbGATT_FORMAT_TYPE_UTF8S = 0x19,
|
||||
cbGATT_FORMAT_TYPE_UTF16S = 0x1A,
|
||||
cbGATT_FORMAT_TYPE_STRUCT = 0x1B,
|
||||
} cbGATT_FormatType;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
// This should map to ATT_TRole
|
||||
cbGATT_ROLE_CLIENT = 0,
|
||||
cbGATT_ROLE_SERVER = 1,
|
||||
cbGATT_ROLE_BOTH = 2
|
||||
} cbGATT_Role;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
cbGATT_NAMESPACE_BT_SIG = 0x01,
|
||||
} cbGATT_Namespace;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
cbGATT_NAMESPACE_DESC_UNKNOWN = 0x0000,
|
||||
} cbGATT_NamespaceDesc;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
cbGATT_FormatType format;
|
||||
cb_uint8 exponent;
|
||||
cbGATT_Unit unit;
|
||||
cbGATT_Namespace gattNamespace;
|
||||
cbGATT_NamespaceDesc namespaceDesc;
|
||||
} cbGATT_CharFormat;
|
||||
|
||||
// This enum must match ATT_TErrorCode for the first two parts
|
||||
// (not the GATT specific)
|
||||
typedef enum
|
||||
{
|
||||
cbGATT_ERROR_CODE_OK = 0x00,
|
||||
cbGATT_ERROR_CODE_INVALID_HANDLE = 0x01,
|
||||
cbGATT_ERROR_CODE_READ_NOT_PERMITTED = 0x02,
|
||||
cbGATT_ERROR_CODE_WRITE_NOT_PERMITTED = 0x03,
|
||||
cbGATT_ERROR_CODE_INVALID_PDU = 0x04,
|
||||
cbGATT_ERROR_CODE_INSUFFICIENT_AUTHENTICATION = 0x05,
|
||||
cbGATT_ERROR_CODE_REQUEST_NOT_SUPPORTED = 0x06,
|
||||
cbGATT_ERROR_CODE_INVALID_OFFSET = 0x07,
|
||||
cbGATT_ERROR_CODE_INSUFFICIENT_AUTHORIZATION = 0x08,
|
||||
cbGATT_ERROR_CODE_PREPARE_FULL_QUEUE = 0x09,
|
||||
cbGATT_ERROR_CODE_ATTRIBUTE_NOT_FOUND = 0x0A,
|
||||
cbGATT_ERROR_CODE_ATTRIBUTE_NOT_LONG = 0x0B,
|
||||
cbGATT_ERROR_CODE_INSUFFICIENT_ENCRYPT_KEY_SIZE = 0x0C,
|
||||
cbGATT_ERROR_CODE_INVALID_ATTRIBUTE_VALUE_LENGTH = 0x0D,
|
||||
cbGATT_ERROR_CODE_UNLIKELY_ERROR = 0x0E,
|
||||
cbGATT_ERROR_CODE_INSUFFICIENT_ENCRYPTION = 0x0F,
|
||||
cbGATT_ERROR_CODE_UNSUPPORTED_GROUP_TPYE = 0x10,
|
||||
cbGATT_ERROR_CODE_INSUFFICIENT_RESOURCES = 0x11,
|
||||
|
||||
cbGATT_ERROR_CODE_OUT_OF_RANGE = 0xFF,
|
||||
cbGATT_ERROR_CODE_PROCEDURE_ALREADY_IN_PROGRESS = 0xFE,
|
||||
cbGATT_ERROR_CODE_IMPROPER_CLIENT_CHAR_CFG = 0xFD,
|
||||
|
||||
// Special error codes not according to BT spec.
|
||||
// Will never be sent over the air.
|
||||
cbGATT_ERROR_CODE_TRANSACTION_TIMEOUT = 0x80,
|
||||
cbGATT_ERROR_CODE_DISCONNECTED = 0x81,
|
||||
cbGATT_ERROR_CODE_RELIABLE_CHECK_FAILED = 0x82,
|
||||
cbGATT_ERROR_CODE_DELAYED_RSP = 0x83,
|
||||
} cbGATT_ErrorCode;
|
||||
|
||||
|
||||
typedef enum
|
||||
{
|
||||
// This must map to ATT_TUuidFormat
|
||||
cbGATT_UUID_16 = 0x01,
|
||||
cbGATT_UUID_128 = 0x02
|
||||
} cbGATT_UuidFormat;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
cbGATT_FINAL_DATA = 0x00,
|
||||
cbGATT_MORE_DATA = 0x01,
|
||||
cbGATT_CANCEL_DATA = 0x02
|
||||
} cbGATT_WriteLongCharFlag;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
// This must map to ATT_TUuid
|
||||
union
|
||||
{
|
||||
cb_uint16 uuid16;
|
||||
cb_uint8 uuid128[16];
|
||||
};
|
||||
cbGATT_UuidFormat format;
|
||||
} cbGATT_Uuid;
|
||||
|
||||
/**
|
||||
* Called when an ACL connection is established
|
||||
* @param handle Connection handle
|
||||
* @param errorCode Connect error code
|
||||
* @param role TODO Add a proper type for role client/server master/slave central/peripheral
|
||||
* @param peerBdAddress Address of remote device
|
||||
* @param connInterval Connection interval
|
||||
* @param connLatency Connection latency
|
||||
* @param connTmo Connection timeout
|
||||
* @param masterClkAccuracy Master clock accuracy
|
||||
* @return None
|
||||
*/
|
||||
typedef void (*cbGATT_ConnComplEvt)(
|
||||
TConnHandle handle,
|
||||
TErrorCode errorCode,
|
||||
cb_uint8 role,
|
||||
TBdAddr peerBdAddress,
|
||||
cb_uint16 connInterval,
|
||||
cb_uint16 connLatency,
|
||||
cb_uint16 connTmo,
|
||||
cb_uint8 masterClkAccuracy);
|
||||
/**
|
||||
* Called when ACL connection is lost.
|
||||
* @param handle Connection handle
|
||||
* @param errorCode Disconnect error code
|
||||
* @return None
|
||||
*/
|
||||
typedef void (*cbGATT_DisconnectEvt)(
|
||||
TConnHandle handle,
|
||||
TErrorCode errorCode);
|
||||
|
||||
|
||||
/*===========================================================================
|
||||
* FUNCTIONS
|
||||
*=========================================================================*/
|
||||
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -0,0 +1,652 @@
|
|||
/*
|
||||
*---------------------------------------------------------------------------
|
||||
* Copyright (c) 2016, u-blox Malmö, All Rights Reserved
|
||||
* SPDX-License-Identifier: LicenseRef-PBL
|
||||
*
|
||||
* This file and the related binary are licensed under the
|
||||
* Permissive Binary License, Version 1.0 (the "License");
|
||||
* you may not use these files except in compliance with the License.
|
||||
*
|
||||
* You may obtain a copy of the License here:
|
||||
* LICENSE-permissive-binary-license-1.0.txt and at
|
||||
* https://www.mbed.com/licenses/PBL-1.0
|
||||
*
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* Component GATT
|
||||
* File cb_gatt_client.h
|
||||
*
|
||||
* Description Definitions and types for GATT client functionality
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file cb_gatt_client.h
|
||||
*
|
||||
* This file contains all GATT client functionality. There are some restrictions
|
||||
* on how this API is used.
|
||||
* - Pointer data in callbacks are only valid in the context of the callback
|
||||
* - Only one request at a time should be done from each app(app handle). The
|
||||
* app must wait until all responses from an outstanding request have been
|
||||
* received.
|
||||
* - In the callback of the request another request can not be done except when
|
||||
* - The request is interrupted by setting the return value to FALSE
|
||||
* or when in the last callback which contains an error code.
|
||||
* - Most of the GATT requests can be interrupted by returning FALSE in the
|
||||
* callback.
|
||||
*
|
||||
* See Bluetooth 4.0 specification for more info on GATT and ATT chapters:
|
||||
* https://www.bluetooth.org/en-us/specification/adopted-specifications
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _CB_GATT_CLIENT_H_
|
||||
#define _CB_GATT_CLIENT_H_
|
||||
|
||||
#include "bt_types.h"
|
||||
#include "cb_gatt.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*==============================================================================
|
||||
* TYPES
|
||||
*==============================================================================
|
||||
*/
|
||||
|
||||
/**
|
||||
* Callback for discover all primary services. This callback will be called
|
||||
* for each primary service found.
|
||||
* @param connHandle Connection handle
|
||||
* @param errorCode cbGATT_ERROR_CODE_OK when succeeded
|
||||
* cbGATT_ERROR_CODE_ATTRIBUTE_NOT_FOUND as last callback
|
||||
* when search is finished.
|
||||
* cbGATT_ERROR_CODE_ on failure
|
||||
* @param startGroupHandle Start handle of the service
|
||||
* @param endGroupHandle End handle of the service
|
||||
* @param pUuid Pointer to UUID of the service
|
||||
* @return TRUE to continue or FALSE to interrupt the search.
|
||||
*/
|
||||
typedef cb_boolean (*cbGATT_DiscoverAllPrimaryServicesCnf)(
|
||||
TConnHandle connHandle,
|
||||
cbGATT_ErrorCode errorCode,
|
||||
cb_uint16 startGroupHandle,
|
||||
cb_uint16 endGroupHandle,
|
||||
cbGATT_Uuid* pUuid);
|
||||
|
||||
/**
|
||||
* Callback for discover all secondary services. This callback will be called
|
||||
* for each secondary service found.
|
||||
* @param connHandle Connection handle
|
||||
* @param errorCode cbGATT_ERROR_CODE_OK when succeeded
|
||||
* cbGATT_ERROR_CODE_ATTRIBUTE_NOT_FOUND as last callback
|
||||
* when search is finished.
|
||||
* cbGATT_ERROR_CODE on failure
|
||||
* @param startGroupHandle Start handle of the service
|
||||
* @param endGroupHandle End handle of the service
|
||||
* @param pUuid Pointer to UUID of the service
|
||||
* @return TRUE to continue or FALSE to interrupt the search.
|
||||
*/
|
||||
typedef cb_boolean (*cbGATT_DiscoverAllSecondaryServicesCnf)(
|
||||
TConnHandle connHandle,
|
||||
cbGATT_ErrorCode errorCode,
|
||||
cb_uint16 startGroupHandle,
|
||||
cb_uint16 endGroupHandle,
|
||||
cbGATT_Uuid* pUuid);
|
||||
|
||||
/**
|
||||
* Callback for discover all primary services by UUID. This callback will be
|
||||
* called for each primary service found.
|
||||
* @param connHandle Connection handle
|
||||
* @param errorCode cbGATT_ERROR_CODE_OK when succeeded
|
||||
* cbGATT_ERROR_CODE_ATTRIBUTE_NOT_FOUND as last callback
|
||||
* when search is finished.
|
||||
* cbGATT_ERROR_CODE_* on failure
|
||||
* @param startGroupHandle Start handle of the service
|
||||
* @param endGroupHandle End handle of the service
|
||||
* @return TRUE to continue or FALSE to interrupt the search.
|
||||
*/
|
||||
typedef cb_boolean (*cbGATT_DiscoverPrimaryServiceByUuidCnf)(
|
||||
TConnHandle connHandle,
|
||||
cbGATT_ErrorCode errorCode,
|
||||
cb_uint16 startHandle,
|
||||
cb_uint16 endHandle);
|
||||
|
||||
/**
|
||||
* Callback for find included services. This callback will be called
|
||||
* for each service found.
|
||||
* @param connHandle Connection handle
|
||||
* @param errorCode cbGATT_ERROR_CODE_OK when succeeded
|
||||
* cbGATT_ERROR_CODE_ATTRIBUTE_NOT_FOUND as last callback
|
||||
* when search is finished.
|
||||
* cbGATT_ERROR_CODE_* on failure
|
||||
* @param startGroupHandle Start handle of the service
|
||||
* @param endGroupHandle End handle of the service
|
||||
* @param pUuid Pointer to UUID of the service
|
||||
* @return TRUE to continue or FALSE to interrupt the search.
|
||||
*/
|
||||
typedef cb_boolean (*cbGATT_FindIncludedServicesCnf)(
|
||||
TConnHandle connHandle,
|
||||
cbGATT_ErrorCode errorCode,
|
||||
cb_uint16 attrHandle,
|
||||
cb_uint16 startGroupHandle,
|
||||
cb_uint16 endGroupHandle,
|
||||
cbGATT_Uuid* pUuid);
|
||||
|
||||
/**
|
||||
* Callback for discover all characteristics of service. This callback will
|
||||
* be called for each characteristic found.
|
||||
* @param connHandle Connection handle
|
||||
* @param errorCode cbGATT_ERROR_CODE_OK when succeeded
|
||||
* cbGATT_ERROR_CODE_ATTRIBUTE_NOT_FOUND as last callback
|
||||
* when search is finished.
|
||||
* cbGATT_ERROR_CODE_* on failure
|
||||
* @param attrHandle Attribute handle of the characteristic
|
||||
* @param properties Bitmap of properties of the characteristic.
|
||||
* See cbGATT_PROP_*.
|
||||
* @param valueHandle Attribute handle of the characteristic value.
|
||||
* This is where the actual data is located.
|
||||
* @param pUuid Pointer to UUID of the characteristic
|
||||
* @return TRUE to continue or FALSE to interrupt the search.
|
||||
*/
|
||||
typedef cb_boolean (*cbGATT_DiscoverAllCharacteristicsOfServiceCnf)(
|
||||
TConnHandle connHandle,
|
||||
cbGATT_ErrorCode errorCode,
|
||||
cb_uint16 attrHandle,
|
||||
cb_uint8 properties,
|
||||
cb_uint16 valueHandle,
|
||||
cbGATT_Uuid* pUuid);
|
||||
|
||||
/**
|
||||
* Callback for discover all descriptors of a characteristic. This callback
|
||||
* will be called for each descriptor found.
|
||||
* @param connHandle Connection handle
|
||||
* @param errorCode cbGATT_ERROR_CODE_OK when succeeded
|
||||
* cbGATT_ERROR_CODE_ATTRIBUTE_NOT_FOUND as last callback
|
||||
* when search is finished.
|
||||
* cbGATT_ERROR_CODE_* on failure
|
||||
* @param charAttrHandle Attribute handle of the characteristic
|
||||
* @param attrHandle Attribute handle of the characteristic descriptor.
|
||||
* @param pUuid Pointer to UUID of the descriptor
|
||||
* @return TRUE to continue or FALSE to interrupt the search.
|
||||
*/
|
||||
typedef cb_boolean (*cbGATT_DiscoverAllCharacteristicDescriptorsCnf)(
|
||||
TConnHandle connHandle,
|
||||
cbGATT_ErrorCode errorCode,
|
||||
cb_uint16 charAttrHandle,
|
||||
cb_uint16 attrHandle,
|
||||
cbGATT_Uuid* pUuid);
|
||||
|
||||
/**
|
||||
* Callback for read characteristic. This callback will be called for each
|
||||
* data chunk read.
|
||||
* The last callback will contain either an error code or moreToRead = FALSE
|
||||
* @param connHandle Connection handle
|
||||
* @param errorCode Error code, cbGATT_ERROR_CODE_OK when succeeded
|
||||
* @param attrHandle Attribute handle of the characteristic
|
||||
* @param pAttrValue Pointer to the read data chunk.
|
||||
* @param length Length of the read data chunk
|
||||
* @param moreToRead TRUE = more data to read from the characteristic
|
||||
* FALSE = no more data to read
|
||||
* @return TRUE to continue or FALSE to interrupt the search.
|
||||
*/
|
||||
typedef cb_boolean (*cbGATT_ReadCharacteristicCnf)(
|
||||
TConnHandle connHandle,
|
||||
cbGATT_ErrorCode errorCode,
|
||||
cb_uint16 attrHandle,
|
||||
cb_uint8* pAttrValue,
|
||||
cb_uint16 length,
|
||||
cb_boolean moreToRead);
|
||||
|
||||
/**
|
||||
* Callback for read characteristic by UUID. This callback will be called
|
||||
* for each data chunk read.
|
||||
* The last callback will contain either an error code or moreToRead = FALSE
|
||||
* @param connHandle Connection handle
|
||||
* @param errorCode Error code, cbGATT_ERROR_CODE_OK when succeeded
|
||||
* @param attrHandle Attribute handle of the characteristic
|
||||
* @param pAttrValue Pointer to the read data chunk.
|
||||
* @param length Length of the read data chunk
|
||||
* @param moreToRead TRUE = more data to read from the characteristic
|
||||
* FALSE = no more data to read
|
||||
* @return TRUE to continue or FALSE to interrupt the search.
|
||||
*/
|
||||
typedef cb_boolean (*cbGATT_ReadCharacteristicByUuidCnf)(
|
||||
TConnHandle connHandle,
|
||||
cbGATT_ErrorCode errorCode,
|
||||
cb_uint16 attrHandle,
|
||||
cb_uint8* pAttrValue,
|
||||
cb_uint16 length,
|
||||
cb_boolean moreToRead);
|
||||
|
||||
// TODO to have or not??
|
||||
typedef void (*cbGATT_ReadLongCharacteristicCnf)(
|
||||
TConnHandle connHandle,
|
||||
cbGATT_ErrorCode errorCode,
|
||||
cb_uint8* pAttrValue,
|
||||
cb_uint16 length);
|
||||
|
||||
/**
|
||||
* Callback for read multiple characteristics. This callback will be called
|
||||
* for each data chunk read.
|
||||
* The last callback will contain either an error code or moreToRead = FALSE
|
||||
* @param connHandle Connection handle
|
||||
* @param errorCode Error code, cbGATT_ERROR_CODE_OK when succeeded
|
||||
* @param pAttrValues Pointer to the read data chunk.
|
||||
* @param length Length of the read data chunk
|
||||
* @param moreToRead TRUE = more data to read from the characteristic(s)
|
||||
* FALSE = no more data to read
|
||||
* @return TRUE to continue or FALSE to interrupt the search.
|
||||
*/
|
||||
typedef cb_boolean (*cbGATT_ReadMultipleCharacteristicCnf)(
|
||||
TConnHandle connHandle,
|
||||
cbGATT_ErrorCode errorCode,
|
||||
cb_uint8* pAttrValues,
|
||||
cb_uint16 length,
|
||||
cb_boolean moreToRead);
|
||||
|
||||
/**
|
||||
* Callback for write characteristic with response from the remote side
|
||||
* @param connHandle Connection handle
|
||||
* @param errorCode Error code, cbGATT_ERROR_CODE_OK when succeeded
|
||||
*/
|
||||
typedef void (*cbGATT_WriteCharacteristicCnf)(
|
||||
TConnHandle connHandle,
|
||||
cbGATT_ErrorCode errorCode);
|
||||
|
||||
/**
|
||||
* Callback for write characteristic with no response from the remote side
|
||||
* @param connHandle Connection handle
|
||||
* @param errorCode Error code, cbGATT_ERROR_CODE_OK when succeeded
|
||||
*/
|
||||
typedef void (*cbGATT_WriteCharacteristicNoRspCnf)(
|
||||
TConnHandle connHandle,
|
||||
cbGATT_ErrorCode errorCode);
|
||||
|
||||
/**
|
||||
* Callback for write characteristic configuration with response from the
|
||||
* remote side.
|
||||
* @param connHandle Connection handle
|
||||
* @param errorCode Error code, cbGATT_ERROR_CODE_OK when succeeded
|
||||
*/
|
||||
typedef void (*cbGATT_WriteCharacteristicConfigCnf)(
|
||||
TConnHandle connHandle,
|
||||
cbGATT_ErrorCode errorCode);
|
||||
|
||||
/**
|
||||
* Callback for write long characteristic with response from the
|
||||
* remote side.
|
||||
* @param connHandle Connection handle
|
||||
* @param errorCode Error code, cbGATT_ERROR_CODE_OK when succeeded
|
||||
*/
|
||||
typedef void (*cbGATT_WriteLongCharacteristicCnf)(
|
||||
TConnHandle connHandle,
|
||||
cbGATT_ErrorCode errorCode);
|
||||
|
||||
/**
|
||||
* Callback for receiving value indication. The client configuration
|
||||
* notifications must have been enabled before this will be sent to the app.
|
||||
* Note that the indication is replied by GATT when exiting the callback.
|
||||
* @param connHandle Connection handle
|
||||
* @param attrHandle Attribute handle of the indicated value
|
||||
* @param pAttrValue Pointer to the value data
|
||||
* @param length Length of the value data
|
||||
*/
|
||||
typedef void (*cbGATT_CharacteristicValueIndication)(
|
||||
TConnHandle connHandle,
|
||||
cb_uint16 attrHandle,
|
||||
cb_uint8* pAttrValue,
|
||||
cb_uint16 length);
|
||||
|
||||
/**
|
||||
* Callback for receiving value notification. The client configuration
|
||||
* notifications must have been enabled before this will be sent to the app.
|
||||
* @param connHandle Connection handle
|
||||
* @param attrHandle Attribute handle of the notified value
|
||||
* @param pAttrValue Pointer to the value data
|
||||
* @param length Length of the value data
|
||||
*/
|
||||
typedef void (*cbGATT_CharacteristicValueNotification)(
|
||||
TConnHandle connHandle,
|
||||
cb_uint16 attrHandle,
|
||||
cb_uint8* pAttrValue,
|
||||
cb_uint16 length);
|
||||
|
||||
typedef struct
|
||||
{
|
||||
cbGATT_ConnComplEvt connComplEvt;
|
||||
cbGATT_DisconnectEvt disconnectEvt;
|
||||
cbGATT_DiscoverAllPrimaryServicesCnf discoverAllPrimaryServicesCnf;
|
||||
cbGATT_DiscoverAllSecondaryServicesCnf discoverAllSecondaryServicesCnf;
|
||||
cbGATT_DiscoverPrimaryServiceByUuidCnf discoverPrimaryServiceByUuidCnf;
|
||||
cbGATT_FindIncludedServicesCnf findIncludedServicesCnf;
|
||||
cbGATT_DiscoverAllCharacteristicsOfServiceCnf discoverAllCharacteristicsOfServiceCnf;
|
||||
cbGATT_DiscoverAllCharacteristicDescriptorsCnf discoverAllCharacteristicDescriptorsCnf;
|
||||
cbGATT_ReadCharacteristicCnf readCharacteristicCnf;
|
||||
cbGATT_ReadCharacteristicByUuidCnf readCharacteristicByUuidCnf;
|
||||
cbGATT_ReadLongCharacteristicCnf readLongCharacteristicCnf;
|
||||
cbGATT_ReadMultipleCharacteristicCnf readMultipleCharacteristicCnf;
|
||||
cbGATT_WriteCharacteristicCnf writeCharacteristicCnf;
|
||||
cbGATT_WriteCharacteristicNoRspCnf writeCharacteristicNoRspCnf;
|
||||
cbGATT_WriteCharacteristicConfigCnf writeCharacteristicConfigCnf;
|
||||
cbGATT_WriteLongCharacteristicCnf writeLongCharacteristicCnf;
|
||||
} cbGATT_ClientCallBack;
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
cbGATT_CharacteristicValueIndication characteristicValueIndication;
|
||||
cbGATT_CharacteristicValueNotification characteristicValueNotification;
|
||||
} cbGATT_ClientNotIndCallBack;
|
||||
|
||||
/*=============================================================================
|
||||
* EXPORTED FUNCTIONS
|
||||
*=============================================================================
|
||||
*/
|
||||
|
||||
/**
|
||||
* Register a GATT client. This must be done before any GATT client
|
||||
* functionality can be used.
|
||||
* @param pCallBack Callback structure that should be provided by the app. Use
|
||||
* NULL as pointer for callbacks that are not used.
|
||||
* @param pAppHandle Pointer where to put created app handle
|
||||
* @return cbGATT_OK if succeeded or cbGATT_ERROR when failed.
|
||||
*/
|
||||
cb_int32 cbGATT_registerClient(
|
||||
const cbGATT_ClientCallBack* pCallBack,
|
||||
cb_uint8* pAppHandle);
|
||||
|
||||
/**
|
||||
* Register a notification/indication handler for an attribute handle
|
||||
* This is used when the application needs a specific handler for an
|
||||
* attribute. This can be done first after connection setup.
|
||||
* @param pCallBack Callback structure that should be provided by the app. Use
|
||||
* NULL as pointer for callbacks that are not used.
|
||||
* @param appHandle App handle
|
||||
* @param attrHandle Attribute handle for the notification/indication to
|
||||
* subscribe on.
|
||||
* @param connHandle Connection handle
|
||||
* @return cbGATT_OK if succeeded or cbGATT_ERROR when failed.
|
||||
*/
|
||||
cb_int32 cbGATT_registerNotIndHandler(
|
||||
const cbGATT_ClientNotIndCallBack* pCallBack,
|
||||
cb_uint8 appHandle,
|
||||
cb_uint16 attrHandle,
|
||||
TConnHandle connHandle);
|
||||
|
||||
/**
|
||||
* De-register a notification/indication handler. This is used when the
|
||||
* app does not want to subscribe to the attribute handle any longer e.g.
|
||||
* the client characteristic configuration has been disabled. The handler is
|
||||
* automatically de-registered on disconnection.
|
||||
* @param pCallBack Registered callback.
|
||||
* @param appHandle App handle
|
||||
* @param attrHandle Attribute handle for the notification/indication to
|
||||
* subscribe on.
|
||||
* @param connHandle Connection handle
|
||||
* @return cbGATT_OK if succeeded or cbGATT_ERROR when failed.
|
||||
*/
|
||||
cb_int32 cbGATT_deregisterNotIndHandler(
|
||||
const cbGATT_ClientNotIndCallBack* pCallBack,
|
||||
cb_uint8 appHandle,
|
||||
cb_uint16 attrHandle,
|
||||
TConnHandle connHandle);
|
||||
|
||||
/**
|
||||
* Register a default notification/indication handler. This is used when the
|
||||
* app wants to subscribe to all attribute handles notifications/indications
|
||||
* for all connections. This can only be used by one app at a time.
|
||||
* @param pCallBack Callback structure that should be provided by the app. Use
|
||||
* NULL as pointer for callbacks that are not used.
|
||||
* @return cbGATT_OK if succeeded or cbGATT_ERROR when failed.
|
||||
*/
|
||||
cb_int32 cbGATT_registerDefaultNotIndHandler(
|
||||
const cbGATT_ClientNotIndCallBack* pCallBack);
|
||||
|
||||
/**
|
||||
* Discover all primary services. Results will be provided in the
|
||||
* cbGATT_DiscoverAllPrimaryServicesCnf callback.
|
||||
* @param connHandle Connection handle
|
||||
* @param appHandle App handle
|
||||
* @return cbGATT_OK if succeeded or cbGATT_ERROR when failed.
|
||||
*/
|
||||
cb_int32 cbGATT_discoverAllPrimaryServices(
|
||||
TConnHandle connHandle,
|
||||
cb_uint8 appHandle);
|
||||
|
||||
/**
|
||||
* Discover all secondary services. Results will be provided in the
|
||||
* cbGATT_DiscoverAllSecondaryServicesCnf callback.
|
||||
* @param connHandle Connection handle
|
||||
* @param appHandle App handle
|
||||
* @return cbGATT_OK if succeeded or cbGATT_ERROR when failed.
|
||||
*/
|
||||
cb_int32 cbGATT_discoverAllSecondaryServices(
|
||||
TConnHandle connHandle,
|
||||
cb_uint8 appHandle);
|
||||
|
||||
/**
|
||||
* Discover all primary services by UUID. This will filter out all results
|
||||
* based on the UUID. Results will be provided in the
|
||||
* cbGATT_DiscoverPrimaryServiceByUuidCnf callback.
|
||||
* @param connHandle Connection handle
|
||||
* @param pUuid Pointer to the 16 or 128 bits UUID to search for
|
||||
* @param appHandle App handle
|
||||
* @return cbGATT_OK if succeeded or cbGATT_ERROR when failed.
|
||||
*/
|
||||
cb_int32 cbGATT_discoverPrimaryServiceByUuid(
|
||||
TConnHandle connHandle,
|
||||
cbGATT_Uuid* pUuid,
|
||||
cb_uint8 appHandle);
|
||||
|
||||
/**
|
||||
* Discover all characteristics of a service. The handles can be
|
||||
* retrieved by doing a discover primary/secondary services request. Results
|
||||
* will be provided in the cbGATT_DiscoverAllCharacteristicsOfServiceCnf
|
||||
* callback.
|
||||
* @param connHandle Connection handle
|
||||
* @param startHandle Start handle of the service
|
||||
* @param endHandle End handle of the service
|
||||
* @param appHandle App handle
|
||||
* @return cbGATT_OK if succeeded or cbGATT_ERROR when failed.
|
||||
*/
|
||||
cb_int32 cbGATT_discoverAllCharacteristicsOfService(
|
||||
TConnHandle connHandle,
|
||||
cb_uint16 startHandle,
|
||||
cb_uint16 endHandle,
|
||||
cb_uint8 appHandle);
|
||||
|
||||
/**
|
||||
* Find included services of a given service. The handles can be
|
||||
* retrieved by doing a discover primary/secondary services request. Results
|
||||
* will be provided in the cbGATT_FindIncludedServicesCnf callback.
|
||||
* @param connHandle Connection handle
|
||||
* @param startHandle Start handle of the service
|
||||
* @param endHandle End handle of the service
|
||||
* @param appHandle App handle
|
||||
* @return cbGATT_OK if succeeded or cbGATT_ERROR when failed.
|
||||
*/
|
||||
cb_int32 cbGATT_findIncludedServices(
|
||||
TConnHandle connHandle,
|
||||
cb_uint16 startHandle,
|
||||
cb_uint16 endHandle,
|
||||
cb_uint8 appHandle);
|
||||
|
||||
/**
|
||||
* Discover all descriptors of a characteristic. The handles can be
|
||||
* retrieved by doing a cbGATT_discoverAllCharacteristicsOfService. Results
|
||||
* will be provided in the cbGATT_DiscoverAllCharacteristicDescriptorsCnf.
|
||||
* callback. If the app wants to do a discover characteristics by UUID this
|
||||
* function can be used and in the callback filter on UUID.
|
||||
* @param connHandle Connection handle
|
||||
* @param valueHandle Handle of the characteristic value
|
||||
* @param serviceEndHandle End handle of the service which the characteristic
|
||||
* belongs to.
|
||||
* @param appHandle App handle
|
||||
* @return cbGATT_OK if succeeded or cbGATT_ERROR when failed.
|
||||
*/
|
||||
cb_int32 cbGATT_discoverAllCharacteristicDescriptors(
|
||||
TConnHandle connHandle,
|
||||
cb_uint16 valueHandle,
|
||||
cb_uint16 serviceEndHandle,
|
||||
cb_uint8 appHandle);
|
||||
|
||||
/**
|
||||
* Read characteristic/descriptor value. The handles can be retrieved by
|
||||
* doing a cbGATT_discoverAllCharacteristicsOfService or
|
||||
* cbGATT_discoverAllCharacteristicDescriptors. Results will be provided in
|
||||
* the cbGATT_ReadCharacteristicCnf callback.
|
||||
* @param connHandle Connection handle
|
||||
* @param attrHandle Handle of the attribute value
|
||||
* @param offset Offset where to start read from
|
||||
* @param appHandle App handle
|
||||
* @return cbGATT_OK if succeeded or cbGATT_ERROR when failed.
|
||||
*/
|
||||
cb_int32 cbGATT_readCharacteristic(
|
||||
TConnHandle connHandle,
|
||||
cb_uint16 attrHandle,
|
||||
cb_uint16 offset,
|
||||
cb_uint8 appHandle);
|
||||
|
||||
/**
|
||||
* Read characteristic/descriptor value by UUID. The app can search the whole
|
||||
* database by using cbGATT_MIN_ATTR_HANDLE and cbGATT_MAX_ATTR_HANDLE.
|
||||
* Results will be provided in the cbGATT_ReadCharacteristicByUuidCnf
|
||||
* callback.
|
||||
* @param connHandle Connection handle
|
||||
* @param startHandle Handle, where to start looking for the UUID
|
||||
* @param endHandle Handle, where to stop looking for the UUID
|
||||
* @param pUuid Pointer to the 16 or 128 bits UUID
|
||||
* @param appHandle App handle
|
||||
* @return cbGATT_OK if succeeded or cbGATT_ERROR when failed.
|
||||
*/
|
||||
cb_int32 cbGATT_readCharacteristicByUuid(
|
||||
TConnHandle connHandle,
|
||||
cb_uint16 startHandle,
|
||||
cb_uint16 endHandle,
|
||||
cbGATT_Uuid* pUuid,
|
||||
cb_uint8 appHandle);
|
||||
|
||||
// Used for reading long characteristics value or descriptor
|
||||
// TODO is this function necessary, because cbGATT_readCharacteristic will read long if needed
|
||||
cb_int32 cbGATT_readLongCharacteristic(
|
||||
TConnHandle connHandle,
|
||||
cb_uint16 attrHandle,
|
||||
cb_uint8* pDest,
|
||||
cb_uint8 appHandle);
|
||||
|
||||
|
||||
/**
|
||||
* Read multiple characteristics in a single read. The app must know the
|
||||
* length of each data element in the returned list. Therefore only the last
|
||||
* data element may have a variable length.
|
||||
* Results will be provided in the cbGATT_ReadMultipleCharacteristicCnf
|
||||
* callback.
|
||||
* @param connHandle Connection handle
|
||||
* @param pAttrHandleList Pointer to a list of attribute handles
|
||||
* @param nbrOfHandles Number of attribute handles in pAttrHandleList
|
||||
* @param appHandle App handle
|
||||
* @return cbGATT_OK if succeeded or cbGATT_ERROR when failed.
|
||||
*/
|
||||
cb_int32 cbGATT_readMultipleCharacteristic(
|
||||
TConnHandle connHandle,
|
||||
cb_uint16* pAttrHandleList,
|
||||
cb_uint16 nbrOfHandles,
|
||||
cb_uint8 appHandle);
|
||||
|
||||
/**
|
||||
* Write characteristic/descriptor and wait for response from remote side.
|
||||
* Results will be provided in the cbGATT_WriteCharacteristicCnf
|
||||
* callback.
|
||||
* @param connHandle Connection handle
|
||||
* @param attrHandle Attribute handle of the value
|
||||
* @param pData Pointer to the data byte sequence
|
||||
* @param length Number of bytes to write
|
||||
* @param appHandle App handle
|
||||
* @return cbGATT_OK if succeeded or cbGATT_ERROR when failed.
|
||||
*/
|
||||
cb_int32 cbGATT_writeCharacteristic(
|
||||
TConnHandle connHandle,
|
||||
cb_uint16 attrHandle,
|
||||
cb_uint8* pData,
|
||||
cb_uint16 length,
|
||||
cb_uint8 appHandle);
|
||||
|
||||
/**
|
||||
* Write client/server characteristic/descriptor configuration.
|
||||
* cbGATT_writeCharacteristic can also be used instead of this function.
|
||||
* Results will be provided in the cbGATT_WriteCharacteristicConfigCnf
|
||||
* callback.
|
||||
* @param connHandle Connection handle
|
||||
* @param attrHandle Attribute handle of the value
|
||||
* @param config Configuration i.e. cbGATT_CLIENT_CFG_* or
|
||||
* cbGATT_SERVER_CFG_*
|
||||
* @param appHandle App handle
|
||||
* @return cbGATT_OK if succeeded or cbGATT_ERROR when failed.
|
||||
*/
|
||||
cb_int32 cbGATT_writeCharacteristicConfig(
|
||||
TConnHandle connHandle,
|
||||
cb_uint16 attrHandle,
|
||||
cb_uint16 config,
|
||||
cb_uint8 appHandle);
|
||||
|
||||
/**
|
||||
* Write characteristic/descriptor with no response from remote side.
|
||||
* Results will be provided in the cbGATT_WriteCharacteristicNoRspCnf
|
||||
* callback.
|
||||
* @param connHandle Connection handle
|
||||
* @param attrHandle Attribute handle of the value
|
||||
* @param pData Pointer to the data byte sequence
|
||||
* @param length Number of bytes to write
|
||||
* @param pSignature Pointer to encrypted signature which is checked by the
|
||||
* server. If the check fails the write is discarded.
|
||||
* The devices must be bonded and CSRK exchanged. Use NULL
|
||||
* when no signature is being used.
|
||||
* @param appHandle App handle
|
||||
* @return cbGATT_OK if succeeded or cbGATT_ERROR when failed.
|
||||
*/
|
||||
cb_int32 cbGATT_writeCharacteristicNoRsp(
|
||||
TConnHandle connHandle,
|
||||
cb_uint16 attrHandle,
|
||||
cb_uint8* pData,
|
||||
cb_uint16 length,
|
||||
cb_uint8* pSignature,
|
||||
cb_uint8 appHandle);
|
||||
|
||||
/**
|
||||
* Write long characteristic/descriptor and wait for response from remote
|
||||
* side. Results will be provided in the cbGATT_WriteLongCharacteristicCnf
|
||||
* callback.
|
||||
* @param connHandle Connection handle
|
||||
* @param attrHandle Attribute handle of the value
|
||||
* @param pData Pointer to the data byte sequence
|
||||
* @param length Number of bytes to write
|
||||
* @param reliable TRUE = the data will be sent back to client and
|
||||
* checked by GATT.
|
||||
* FALSE = no check of data
|
||||
* @param flag Flag which is used when sending several packets
|
||||
* or when data is canceled. If sending several packets all
|
||||
* but the last packet should set the flag to more data.
|
||||
* The last data packet should set the flag to final.
|
||||
* @param offset Offset of the data to write. Is used when several packets
|
||||
* need to be sent to write a complete data value.
|
||||
* @param appHandle App handle
|
||||
* @return cbGATT_OK if succeeded or cbGATT_ERROR when failed.
|
||||
*/
|
||||
cb_int32 cbGATT_writeLongCharacteristic(
|
||||
TConnHandle connHandle,
|
||||
cb_uint16 attrHandle,
|
||||
cb_uint8* pData,
|
||||
cb_uint16 length,
|
||||
cb_boolean reliable,
|
||||
cbGATT_WriteLongCharFlag flag,
|
||||
cb_uint16 offset,
|
||||
cb_uint8 appHandle);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -0,0 +1,329 @@
|
|||
/*------------------------------------------------------------------------------
|
||||
* Copyright (c) 2016, u-blox Malmö, All Rights Reserved
|
||||
* SPDX-License-Identifier: LicenseRef-PBL
|
||||
*
|
||||
* This file and the related binary are licensed under the
|
||||
* Permissive Binary License, Version 1.0 (the "License");
|
||||
* you may not use these files except in compliance with the License.
|
||||
*
|
||||
* You may obtain a copy of the License here:
|
||||
* LICENSE-permissive-binary-license-1.0.txt and at
|
||||
* https://www.mbed.com/licenses/PBL-1.0
|
||||
*
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*------------------------------------------------------------------------------
|
||||
* Component: GATT
|
||||
* File : cb_gatt_server.h
|
||||
*
|
||||
* Description:
|
||||
* GATT server functionality
|
||||
*------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file cb_gatt_server.h
|
||||
*
|
||||
* @brief GATT server functionality
|
||||
*/
|
||||
|
||||
#ifndef _CB_GATT_SERVER_H_
|
||||
#define _CB_GATT_SERVER_H_
|
||||
|
||||
#include "bt_types.h"
|
||||
#include "cb_gatt.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*==============================================================================
|
||||
* CONSTANTS
|
||||
*==============================================================================
|
||||
*/
|
||||
|
||||
#define cbGATT_RD_SEC_NONE 0x01
|
||||
#define cbGATT_RD_SEC_UNAUTH 0x02
|
||||
#define cbGATT_RD_SEC_AUTH 0x04
|
||||
#define cbGATT_WR_SEC_NONE 0x10
|
||||
#define cbGATT_WR_SEC_UNAUTH 0x20
|
||||
#define cbGATT_WR_SEC_AUTH 0x40
|
||||
|
||||
#define cbGATT_NBR_OF_ATTR_OF_SERVICE(x) (sizeof(x)/sizeof(cbGATT_Attribute))
|
||||
|
||||
#define cbGATT_APP_START_SERVICE_HANDLE 1024
|
||||
|
||||
/*==============================================================================
|
||||
* TYPES
|
||||
*==============================================================================
|
||||
*/
|
||||
|
||||
/**
|
||||
* Attribute database entry
|
||||
* @param pUuid 16 or 128-bits UUID
|
||||
* @param uuidFormat Format of the pUuid
|
||||
* @param properties Properties see cbGATT_PROP_* in cb_gatt.h
|
||||
* @param security Read/write security properties for this characteristic see cbGATT_WR_SEC_* and cbGATT_RD_SEC_*
|
||||
* @param pvValue1 Depends on pUuid, see below
|
||||
* cbGATT_CHAR_EXT_PROP - properties as cb_uint32
|
||||
* cbGATT_CLIENT_CHAR_CONFIG - callback that is called when remote device reads the client config, cbGATT_ServerReadClientConfig
|
||||
* cbGATT_SERVER_CHAR_CONFIG - callback that is called when remote device reads the server config, cbGATT_ServerReadServerConfig
|
||||
* cbGATT_CHAR_FORMAT - Pointer to cbGATT_CharFormat
|
||||
* cbGATT_CHAR_USER_DESC and all other CHARACTERISTICS value - cbGATT_ServerReadAttr callback
|
||||
* cbGATT_INCLUDE_DECL - Pointer to inlcuded service cbGATT_Attribute
|
||||
* @param pvValue2 Depends on pUuid, see below
|
||||
* cbGATT_CLIENT_CHAR_CONFIG - callback that is called when remote device writes the client config cbGATT_ServerWriteClientConfig
|
||||
* cbGATT_CLIENT_CHAR_CONFIG - callback that is called when remote device writes the client config cbGATT_ServerWriteClientConfig
|
||||
* cbGATT_SERVER_CHAR_CONFIG - callback that is called when remote device writes the server config cbGATT_ServerWriteServerConfig
|
||||
* cbGATT_CHAR_USER_DESC and all other CHARACTERISTICS value - cbGATT_ServerWriteAttr callback
|
||||
* @param pAttrHandle Pointer where to write the attribute handle in case it's needed by the app.
|
||||
* If not needed, pass NULL. Will be written after the service has been added.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
void* pUuid;
|
||||
cbGATT_UuidFormat uuidFormat;
|
||||
cb_uint8 properties;
|
||||
cb_uint8 security;
|
||||
void* pvValue1;
|
||||
void* pvValue2;
|
||||
cb_uint16* pAttrHandle;
|
||||
} cbGATT_Attribute;
|
||||
|
||||
/**
|
||||
* Callback is called when the indication has been confirmed.
|
||||
* @param connHandle Connection handle
|
||||
* @param attrHandle Handle of the attribute value
|
||||
* @param errorCode cbGATT_ERROR_CODE_OK when succeeded
|
||||
*/
|
||||
typedef void (*cbGATT_CharacteristicValueIndicationCnf)(
|
||||
TConnHandle connHandle,
|
||||
cb_uint16 attrHandle,
|
||||
cbGATT_ErrorCode errorCode);
|
||||
|
||||
/**
|
||||
* Callback is called when the notification has been sent.
|
||||
* @param connHandle Connection handle
|
||||
* @param errorCode cbGATT_ERROR_CODE_OK when succeeded
|
||||
*/
|
||||
typedef void (*cbGATT_CharacteristicValueNotificationCnf)(
|
||||
TConnHandle connHandle,
|
||||
cbGATT_ErrorCode errorCode);
|
||||
|
||||
/**
|
||||
* Callback is called when the GATT client has commited a write long
|
||||
* @param connHandle Connection handle
|
||||
* @param commit TRUE = commit, FALSE = cancel
|
||||
* @return cbGATT_ERROR_CODE_OK if accepted or some cbGATT_ERROR_CODE_* code when failed.
|
||||
*/
|
||||
typedef cbGATT_ErrorCode (*cbGATT_CharacteristicWriteLongCommitEvt)(
|
||||
TConnHandle connHandle,
|
||||
cb_boolean commit);
|
||||
|
||||
// Callbacks to use in server table
|
||||
|
||||
/**
|
||||
* Callback is called when the client is reading an attribute
|
||||
* @param connHandle Connection handle
|
||||
* @param attrHandle Handle of the attribute value
|
||||
* @param pAttr Pointer to attribute record
|
||||
* @param pAttrValue Pointer where to put the read data
|
||||
* @param pLength Pointer where to put the read length.
|
||||
* @param maxLength Max number of bytes that is allowed for pAttrValue
|
||||
* @param offset The offset of the read data
|
||||
* @return cbGATT_ERROR_CODE_OK if accepted or some cbGATT_ERROR_CODE_* code when failed.
|
||||
*/
|
||||
typedef cbGATT_ErrorCode (*cbGATT_ServerReadAttr)(
|
||||
TConnHandle connHandle,
|
||||
cb_uint16 attrHandle,
|
||||
cbGATT_Attribute* pAttr,
|
||||
cb_uint8* pAttrValue,
|
||||
cb_uint16* pLength,
|
||||
cb_uint16 maxLength,
|
||||
cb_uint16 offset);
|
||||
|
||||
/**
|
||||
* Callback is called when the client is writing an attribute.
|
||||
* If the application wants to send the response later it can
|
||||
* return the cbGATT_ERROR_CODE_DELAYED_RSP error code and call cbGATT_writeRsp
|
||||
* when ready.
|
||||
* @param connHandle Connection handle
|
||||
* @param attrHandle Handle of the attribute value
|
||||
* @param pAttr Pointer to attribute record
|
||||
* @param pAttrValue Pointer where to get the data
|
||||
* @param length The length.
|
||||
* @param writeMethod Which write method the client is using.
|
||||
* This depends on the properties in the attribute table.
|
||||
* @param offset The offset of the written data
|
||||
* @return cbGATT_ERROR_CODE_OK if accepted or some cbGATT_ERROR_CODE_* code when failed.
|
||||
*/
|
||||
typedef cbGATT_ErrorCode (*cbGATT_ServerWriteAttr)(
|
||||
TConnHandle connHandle,
|
||||
cb_uint16 attrHandle,
|
||||
cbGATT_Attribute* pAttr,
|
||||
cb_uint8* pAttrValue,
|
||||
cb_uint16 length,
|
||||
cbGATT_WriteMethod writeMethod,
|
||||
cb_uint16 offset);
|
||||
|
||||
/**
|
||||
* Callback is called when the client is reading the client config
|
||||
* @param connHandle Connection handle
|
||||
* @param attrHandle Handle of the attribute value
|
||||
* @param pConfig Pointer where to write the config
|
||||
* @return cbGATT_ERROR_CODE_OK if accepted or some cbGATT_ERROR_CODE_* code when failed.
|
||||
*/
|
||||
typedef cbGATT_ErrorCode (*cbGATT_ServerReadClientConfig)(
|
||||
TConnHandle connHandle,
|
||||
cb_uint16 attrHandle,
|
||||
cb_uint16* pConfig);
|
||||
|
||||
/**
|
||||
* Callback is called when the client is writing the client config
|
||||
* @param connHandle Connection handle
|
||||
* @param attrHandle Handle of the attribute value
|
||||
* @param config The config to be stored
|
||||
* @param writeMethod Which write method the client is using.
|
||||
* This depends on the properties in the attribute table.
|
||||
* @return cbGATT_ERROR_CODE_OK if accepted or some cbGATT_ERROR_CODE_* code when failed.
|
||||
*/
|
||||
typedef cbGATT_ErrorCode (*cbGATT_ServerWriteClientConfig)(
|
||||
TConnHandle connHandle,
|
||||
cb_uint16 attrHandle,
|
||||
cb_uint16 config,
|
||||
cbGATT_WriteMethod writeMethod);
|
||||
|
||||
/**
|
||||
* Callback is called when the client is reading the server config
|
||||
* @param connHandle Connection handle
|
||||
* @param attrHandle Handle of the attribute value
|
||||
* @param pConfig Pointer where to write the config
|
||||
* @return cbGATT_ERROR_CODE_OK if accepted or some cbGATT_ERROR_CODE_* code when failed.
|
||||
*/
|
||||
typedef cbGATT_ErrorCode (*cbGATT_ServerReadServerConfig)(
|
||||
TConnHandle connHandle,
|
||||
cb_uint16 attrHandle,
|
||||
cb_uint16* pConfig);
|
||||
|
||||
/**
|
||||
* Callback is called when the client is writing the server config
|
||||
* @param connHandle Connection handle
|
||||
* @param attrHandle Handle of the attribute value
|
||||
* @param config The config to be stored
|
||||
* @param writeMethod Which write method the client is using.
|
||||
* This depends on the properties in the attribute table.
|
||||
* @return cbGATT_ERROR_CODE_OK if accepted or some cbGATT_ERROR_CODE_* code when failed.
|
||||
*/
|
||||
typedef cbGATT_ErrorCode (*cbGATT_ServerWriteServerConfig)(
|
||||
TConnHandle connHandle,
|
||||
cb_uint16 attrHandle,
|
||||
cb_uint16 config,
|
||||
cbGATT_WriteMethod writeMethod);
|
||||
|
||||
typedef struct
|
||||
{
|
||||
cbGATT_ConnComplEvt connComplEvt;
|
||||
cbGATT_DisconnectEvt disconnectEvt;
|
||||
cbGATT_CharacteristicValueIndicationCnf characteristicValueIndicationCnf;
|
||||
cbGATT_CharacteristicValueNotificationCnf characteristicValueNotificationCnf;
|
||||
cbGATT_CharacteristicWriteLongCommitEvt characteristicWriteLongCommitEvt;
|
||||
} cbGATT_ServerCallBack;
|
||||
|
||||
|
||||
/*=============================================================================
|
||||
* EXPORTED FUNCTIONS
|
||||
*=============================================================================
|
||||
*/
|
||||
|
||||
/**
|
||||
* Register server callbacks
|
||||
* @param pCallBack Server callback
|
||||
* @param pAppHandle Where to store app handle
|
||||
* @return cbGATT_OK if succeeded or cbGATT_ERROR when failed.
|
||||
*/
|
||||
cb_int32 cbGATT_registerServer(
|
||||
const cbGATT_ServerCallBack* pCallBack,
|
||||
cb_uint8* pAppHandle);
|
||||
|
||||
/**
|
||||
* Deregister all server callbacks
|
||||
* @return cbGATT_OK if succeeded or cbGATT_ERROR when failed.
|
||||
*/
|
||||
cb_int32 cbGATT_deregisterAllServers(void);
|
||||
|
||||
/**
|
||||
* Send notification to GATT client. The characteristicValueNotificationCnf
|
||||
* callback will be called when finished and a new notification can be sent.
|
||||
* The client config notification must have been enabled by the GATT client
|
||||
* before an notification can be sent.
|
||||
* @param connHandle Connection handle
|
||||
* @param attrHandle Handle of the attribute value
|
||||
* @param pData Pointer to data to send
|
||||
* @param length Length of pData
|
||||
* @param appHandle App handle
|
||||
* @return cbGATT_OK if succeeded or some cbGATT_ERROR* when failed.
|
||||
*/
|
||||
cb_int32 cbGATT_notification(
|
||||
TConnHandle connHandle,
|
||||
cb_uint16 attrHandle,
|
||||
cb_uint8* pData,
|
||||
cb_uint16 length,
|
||||
cb_uint8 appHandle);
|
||||
|
||||
/**
|
||||
* Send indication to GATT client. The characteristicValueIndicationCnf
|
||||
* callback will be called when finished and a new indication can be sent.
|
||||
* The client config indication must have been enabled by the GATT client
|
||||
* before an indication can be sent.
|
||||
* @param connHandle Connection handle
|
||||
* @param attrHandle Handle of the attribute value
|
||||
* @param pData Pointer to data to send
|
||||
* @param length Length of pData
|
||||
* @param appHandle App handle
|
||||
* @return cbGATT_OK if succeeded or some cbGATT_ERROR* when failed.
|
||||
*/
|
||||
cb_int32 cbGATT_indication(
|
||||
TConnHandle connHandle,
|
||||
cb_uint16 attrHandle,
|
||||
cb_uint8* pData,
|
||||
cb_uint16 length,
|
||||
cb_uint8 appHandle);
|
||||
|
||||
/**
|
||||
* Delay write respone to client, see cbGATT_ServerWriteAttr
|
||||
* @param connHandle Connection handle
|
||||
* @param attrHandle Handle of the attribute value
|
||||
* @param errorCode Error code, use cbGATT_ERROR_CODE_OK if OK otherwise some cbGATT_ERROR_CODE_*
|
||||
* @return cbGATT_OK if succeeded or some cbGATT_ERROR* when failed.
|
||||
*/
|
||||
cb_int32 cbGATT_writeRsp(
|
||||
TConnHandle connHandle,
|
||||
cb_uint16 attrHandle,
|
||||
cb_uint8 errorCode); // For delayed write responses
|
||||
|
||||
/**
|
||||
* Add service list to attribute database
|
||||
* @param pAttrList Attribute list
|
||||
* @param attrListSize Size of the attribute list
|
||||
* @param startHandle Start handle. Note that startHandle for the application
|
||||
* should start at lowest 1024, cbGATT_APP_START_SERVICE_HANDLE.
|
||||
* 1-1023 is reserved for GATT/GAP and other u-blox services.
|
||||
* @return cbGATT_OK if succeeded or some cbGATT_ERROR* when failed.
|
||||
*/
|
||||
cb_int32 cbGATT_addService(
|
||||
const cbGATT_Attribute* pAttrList,
|
||||
cb_uint16 attrListSize,
|
||||
cb_int16 startHandle);
|
||||
|
||||
/**
|
||||
* NOTE: Only for tests
|
||||
* Free all services. Use with care since this will also remove GATT and GAP services.
|
||||
* @return cbGATT_OK if succeeded or some cbGATT_ERROR* when failed.
|
||||
*/
|
||||
cb_int32 cbGATT_freeServices(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -0,0 +1,104 @@
|
|||
/*
|
||||
*---------------------------------------------------------------------------
|
||||
* Copyright (c) 2016, u-blox Malmö, All Rights Reserved
|
||||
* SPDX-License-Identifier: LicenseRef-PBL
|
||||
*
|
||||
* This file and the related binary are licensed under the
|
||||
* Permissive Binary License, Version 1.0 (the "License");
|
||||
* you may not use these files except in compliance with the License.
|
||||
*
|
||||
* You may obtain a copy of the License here:
|
||||
* LICENSE-permissive-binary-license-1.0.txt and at
|
||||
* https://www.mbed.com/licenses/PBL-1.0
|
||||
*
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* Component : GATT
|
||||
* File : cb_gatt_utils.h
|
||||
*
|
||||
* Description : Helper functions for GATT
|
||||
*
|
||||
*-------------------------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
* @file cb_gatt_utils.h
|
||||
*
|
||||
* @brief Helper functions for GATT
|
||||
*/
|
||||
|
||||
#ifndef _CB_GATT_UTILS_H_
|
||||
#define _CB_GATT_UTILS_H_
|
||||
|
||||
#include "cb_comdefs.h"
|
||||
#include "bt_types.h"
|
||||
#include "cb_gatt.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*=============================================================================
|
||||
* FUNCTIONS
|
||||
*=============================================================================
|
||||
*/
|
||||
|
||||
/**
|
||||
* Returns a string representing the error code. NULL if the error code is
|
||||
* not found.
|
||||
* @param errorCode GATT error code
|
||||
*/
|
||||
cb_char* cbGATT_UTILS_getStringFromErrorCode(
|
||||
cbGATT_ErrorCode errorCode);
|
||||
|
||||
/**
|
||||
* Returns a string representing the GATT/ATT properties for a characteristic.
|
||||
* @param properties Bitmap of properties see cbGATT_PROP_*
|
||||
*/
|
||||
cb_char* cbGATT_UTILS_getStringFromProperties(
|
||||
cb_uint8 properties);
|
||||
|
||||
/**
|
||||
* Returns a string representing the UUID. NULL if the UUID is not
|
||||
* found.
|
||||
* @param pUuid Pointer to 128 or 16-bit UUID
|
||||
*/
|
||||
cb_char* cbGATT_UTILS_getStringFromUuid(
|
||||
cbGATT_Uuid* pUuid);
|
||||
|
||||
/**
|
||||
* Returns a string representing the UUID as hex bytes.
|
||||
* @param pUuid Pointer to 128 or 16-bit UUID
|
||||
* @param resultStr Allocated buffer to put hex string in.
|
||||
* Should fit 16*2+1 = 33 bytes
|
||||
*/
|
||||
cb_char* cbGATT_UTILS_getHexStringFromUuid(
|
||||
cbGATT_Uuid* pUuid,
|
||||
cb_char* resultStr);
|
||||
|
||||
/**
|
||||
* Returns a string representing the data as hex bytes.
|
||||
* @param pData Pointer to data
|
||||
* @param len Length of data
|
||||
* @param resultStr Pointer to allocated buffer to put hex string in.
|
||||
* Should fit len*2+1 bytes
|
||||
*/
|
||||
cb_char* cbGATT_UTILS_dataToHex(
|
||||
cb_uint8* pData,
|
||||
cb_uint16 len,
|
||||
cb_char* resultStr);
|
||||
|
||||
/**
|
||||
* Reverse bytes
|
||||
* @param src Pointer to data to reverse bytes for
|
||||
* @param nbrOfBytes Length of src
|
||||
*/
|
||||
void cbGATT_UTILS_reverseBytes(
|
||||
cb_uint8* src,
|
||||
cb_uint16 nbrOfBytes);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -0,0 +1,146 @@
|
|||
/*---------------------------------------------------------------------------
|
||||
* Copyright (c) 2016, u-blox Malmö, All Rights Reserved
|
||||
* SPDX-License-Identifier: LicenseRef-PBL
|
||||
*
|
||||
* This file and the related binary are licensed under the
|
||||
* Permissive Binary License, Version 1.0 (the "License");
|
||||
* you may not use these files except in compliance with the License.
|
||||
*
|
||||
* You may obtain a copy of the License here:
|
||||
* LICENSE-permissive-binary-license-1.0.txt and at
|
||||
* https://www.mbed.com/licenses/PBL-1.0
|
||||
*
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* Component: CB HW
|
||||
* File : cb_hw.h
|
||||
*
|
||||
* Description: Setup of hardware.
|
||||
* TODO clean up this interface..
|
||||
*-------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef _CB_HW_H_
|
||||
#define _CB_HW_H_
|
||||
|
||||
#include "cb_comdefs.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*===========================================================================
|
||||
* DEFINES
|
||||
*=========================================================================*/
|
||||
typedef enum {
|
||||
cbHW_PCB_VERSION_UNKNOWN,
|
||||
cbHW_PCB_VERSION_1,
|
||||
cbHW_PCB_VERSION_2,
|
||||
cbHW_PCB_VERSION_3,
|
||||
cbHW_PCB_VERSION_4,
|
||||
cbHW_PCB_VERSION_5
|
||||
} cbHW_PCBVersion;
|
||||
|
||||
typedef enum {
|
||||
cbHW_RESET_REASON_UNKNOWN = 0,
|
||||
cbHW_RESET_REASON_FW_UPDATE,
|
||||
cbHW_RESET_REASON_PRODUCTION_MODE
|
||||
}cbHW_ResetReason;
|
||||
|
||||
typedef enum {
|
||||
cbHW_FLOW_CONTROL_DISABLED = 0,
|
||||
cbHW_FLOW_CONTROL_ENABLED
|
||||
} cbHW_FlowControl;
|
||||
|
||||
typedef enum {
|
||||
cbHW_IRQ_HIGH = 2U,
|
||||
cbHW_IRQ_MEDIUM = 3U,
|
||||
cbHW_IRQ_DEFAULT = 5U,
|
||||
cbHW_IRQ_LOW = 12U
|
||||
}cbHW_PRIO_LVL;
|
||||
|
||||
/*===========================================================================
|
||||
* TYPES
|
||||
*=========================================================================*/
|
||||
|
||||
typedef void (*cbHW_StopModeStatusEvt)(cb_boolean enable);
|
||||
typedef void (*cbHW_SysTickCb)(void);
|
||||
|
||||
/*===========================================================================
|
||||
* FUNCTIONS
|
||||
*=========================================================================*/
|
||||
|
||||
void cbHW_init(void);
|
||||
void cbHW_registerStopModeStatusEvt(cbHW_StopModeStatusEvt evt);
|
||||
void cbHW_disableIrq(void);
|
||||
void cbHW_disableAllIrq(void); // Should not be used unless extremely critical
|
||||
void cbHW_enableIrq(void);
|
||||
void cbHW_enterSleepMode(void);
|
||||
void cbHW_enterStopMode(void);
|
||||
void cbHW_setWakeupEvent(void);
|
||||
void cbHW_resetWakeupEvent(void);
|
||||
|
||||
/**
|
||||
* Wait for specified amount of microseconds. May be interrupt dependent.
|
||||
* @note Granularity may vary between systems. Will be at least systick based.
|
||||
* The system may go to sleep during the delay.
|
||||
*
|
||||
* @param us Time to delay in microseconds.
|
||||
*/
|
||||
void cbHW_delay(cb_uint32 us);
|
||||
|
||||
/**
|
||||
* Wait for specified amount of microseconds using a software loop.
|
||||
* @note Granularity may vary between systems.
|
||||
* The system will not go to sleep during the delay.
|
||||
*
|
||||
* @param us Time to delay in microseconds.
|
||||
*/
|
||||
void cbHW_softDelay(cb_uint32 us);
|
||||
cb_boolean cbHW_sysFreqIsSupported(cb_uint32 sysFreq);
|
||||
void cbHW_setSysFreq(cb_uint32 sysFreq);
|
||||
cb_uint32 cbHW_getSysFreq(void);
|
||||
void cbHW_writeBackupRegister(cb_uint32 registerId, cb_uint32 value);
|
||||
cb_uint32 cbHW_readBackupRegister(cb_int32 registerId);
|
||||
void cbHW_getHWId(cb_uint8 uid[12]);
|
||||
cbHW_PCBVersion cbHW_getPCBVersion(void);
|
||||
|
||||
/**
|
||||
* Register a system tick callback.
|
||||
* The system tick will be generated once evert millisecond.
|
||||
*
|
||||
* @param cb Callback function for the system tick timer.
|
||||
*/
|
||||
void cbHW_registerSysTickISRCallback(cbHW_SysTickCb cb);
|
||||
|
||||
/**
|
||||
* Get the current tick frequency for the @ref cbHW_getTicks tick counter.
|
||||
* @note The frequency may be altered with different system clocks and power modes.
|
||||
*
|
||||
* @return The current tick frequency.
|
||||
*/
|
||||
cb_uint32 cbHW_getTickFrequency(void);
|
||||
|
||||
/**
|
||||
* Get the current value of the tick counter.
|
||||
* Time base in @ref cbHW_getTickFrequency.
|
||||
* @note The value may wrap.
|
||||
*
|
||||
* @return The current tick counter.
|
||||
*/
|
||||
cb_uint32 cbHW_getTicks(void);
|
||||
|
||||
void cbHW_forceBoot(cb_uint32 address, cb_uint32 baudrate);
|
||||
void cbHW_enterProductionMode(cbHW_FlowControl flowControl);
|
||||
cbHW_ResetReason cbHW_resetReason(void);
|
||||
cbHW_FlowControl cbHW_flowControl(void);
|
||||
|
||||
void cbHW_enableAllIrq(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
|
@ -0,0 +1,131 @@
|
|||
/*---------------------------------------------------------------------------
|
||||
* Copyright (c) 2016, u-blox Malmö, All Rights Reserved
|
||||
* SPDX-License-Identifier: LicenseRef-PBL
|
||||
*
|
||||
* This file and the related binary are licensed under the
|
||||
* Permissive Binary License, Version 1.0 (the "License");
|
||||
* you may not use these files except in compliance with the License.
|
||||
*
|
||||
* You may obtain a copy of the License here:
|
||||
* LICENSE-permissive-binary-license-1.0.txt and at
|
||||
* https://www.mbed.com/licenses/PBL-1.0
|
||||
*
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* Component: Main for WiFi-driver and BT stack
|
||||
* File : cb_main.h
|
||||
*
|
||||
* Description :
|
||||
*-------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef _CB_MAIN_H_
|
||||
#define _CB_MAIN_H_
|
||||
|
||||
#include "bt_types.h"
|
||||
#include "cb_bt_man.h"
|
||||
#include "cb_wlan.h"
|
||||
#include "mbed_events.h"
|
||||
|
||||
/*===========================================================================
|
||||
* DEFINES
|
||||
*=========================================================================*/
|
||||
#define cbMAIN_TARGET_INVALID_ID -1
|
||||
|
||||
/*===========================================================================
|
||||
* TYPES
|
||||
*=========================================================================*/
|
||||
typedef struct
|
||||
{
|
||||
TBdAddr address; /** Bluetooth address that shall be assigned to controller. Pass invalidBdAddress to use controller default address*/
|
||||
cbBM_LeRole leRole; /** Bluetooth low energy role */
|
||||
cb_int8 maxOutputPower; /** Maximum output power. */
|
||||
cb_uint32 maxLinkKeysClassic; /** Max number of CLASSIC link keys */
|
||||
cb_uint32 maxLinkKeysLe; /** Max number of link keys BLE*/
|
||||
} cbMAIN_BtInitParams;
|
||||
|
||||
typedef void(*cbMAIN_ErrorHandler)(
|
||||
cb_int32 errorCode,
|
||||
const cb_char* filename,
|
||||
cb_uint32 line);
|
||||
|
||||
/*---------------------------------------------------------------------------
|
||||
* Callback to indicate that initialization of BT stack is completed.
|
||||
*-------------------------------------------------------------------------*/
|
||||
typedef void(*cbMAIN_initBtComplete)(void);
|
||||
|
||||
/*===========================================================================
|
||||
* FUNCTIONS
|
||||
*=========================================================================*/
|
||||
|
||||
/**
|
||||
* Initialize OS, timers, GPIO's, heap and OTP.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
extern void cbMAIN_initOS(void);
|
||||
|
||||
/**
|
||||
* Start Bluetooth HW.
|
||||
*
|
||||
* @param pInitParameters Initial configuration parameters. These parameters can
|
||||
* not be changed once Bluetooth has been started.
|
||||
* @param callback Will be invoked when initialisation is done.
|
||||
* @return void
|
||||
*/
|
||||
extern void cbMAIN_initBt(cbMAIN_BtInitParams *pInitParameters, cbMAIN_initBtComplete callback);
|
||||
|
||||
/**
|
||||
* Initialize WLAN component.
|
||||
* @return Port specific TARGET identifier
|
||||
*/
|
||||
extern cb_int32 cbMAIN_initWlan(void);
|
||||
|
||||
/**
|
||||
* Start WLAN component.
|
||||
* Create WLAN driver instance, bind it to targetId and start the driver.
|
||||
*
|
||||
* @param targetId Port specific TARGET identifier.
|
||||
* @param params Start parameters passed to WLAN driver instance.
|
||||
* @return cbSTATUS_OK if successful, otherwise cbSTATUS_ERROR.
|
||||
*/
|
||||
extern cb_int32 cbMAIN_startWlan(cb_int32 targetId, cbWLAN_StartParameters *params);
|
||||
|
||||
/**
|
||||
* Register error handler function.
|
||||
*
|
||||
* @param errHandler Function to be invoked in case of error.
|
||||
* @return void
|
||||
*/
|
||||
extern void cbMAIN_registerErrorHandler(cbMAIN_ErrorHandler errHandler);
|
||||
|
||||
/**
|
||||
* Start driver OS. This must be called after all cbMAIN_initOS/cbMAIN_initBt/cbMAIN_initWlan
|
||||
* to start the driver thread.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
extern void cbMAIN_startOS(void);
|
||||
|
||||
/**
|
||||
* Get event queue. Used for running a function in the same thread context as the driver.
|
||||
* Can not be called before cbMAIN_initOS/cbMAIN_initBt/cbMAIN_initWlan.
|
||||
* @return EventQueue Pointer to the event queue where function calls can be enqueued.
|
||||
*/
|
||||
extern EventQueue* cbMAIN_getEventQueue(void);
|
||||
|
||||
/**
|
||||
* Lock driver from usage. This must be used if a C API function is used outside of the driver thread context.
|
||||
* The driver should only be locked for as small time as possible.
|
||||
* @return void
|
||||
*/
|
||||
extern void cbMAIN_driverLock(void);
|
||||
|
||||
/**
|
||||
* Unlock driver. used when the C API function has finished executing to release the driver for others to use.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
extern void cbMAIN_driverUnlock(void);
|
||||
|
||||
#endif /*_CB_MAIN_H_*/
|
|
@ -0,0 +1,68 @@
|
|||
/*---------------------------------------------------------------------------
|
||||
* Copyright (c) 2016, u-blox Malmö, All Rights Reserved
|
||||
* SPDX-License-Identifier: LicenseRef-PBL
|
||||
*
|
||||
* This file and the related binary are licensed under the
|
||||
* Permissive Binary License, Version 1.0 (the "License");
|
||||
* you may not use these files except in compliance with the License.
|
||||
*
|
||||
* You may obtain a copy of the License here:
|
||||
* LICENSE-permissive-binary-license-1.0.txt and at
|
||||
* https://www.mbed.com/licenses/PBL-1.0
|
||||
*
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* Component : OTP
|
||||
* File : cb_otp.h
|
||||
*
|
||||
* Description : Support for One Time Programmable memory intended for
|
||||
* storing production parameters such as mac addresses, trim
|
||||
* values and product configuration. Writing to OTP memory shall
|
||||
* only be done in a production environment.
|
||||
*-------------------------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
* @file cb_otp.h
|
||||
* @ingroup platform
|
||||
*/
|
||||
|
||||
#ifndef _CB_OTP_H_
|
||||
#define _CB_OTP_H_
|
||||
|
||||
#include "cb_comdefs.h"
|
||||
#include "cb_status.h"
|
||||
|
||||
#define cbOTP_MAX_SIZE (30)
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef enum
|
||||
{
|
||||
cbOTP_MAC_BLUETOOTH = 1,
|
||||
cbOTP_MAC_WLAN,
|
||||
cbOTP_MAC_ETHERNET,
|
||||
cbOTP_MAC_FEATURE_INFO,
|
||||
cbOTP_MAC_DEBUG_UNIT,
|
||||
cbOTP_SERIAL_NUMBER,
|
||||
cbOTP_TYPE_CODE,
|
||||
cbOTP_RESERVED_UNUSED = 255
|
||||
} cbOTP_Id;
|
||||
|
||||
|
||||
/**
|
||||
* Read a OTP parameter
|
||||
* @param id The id of the parameter to write
|
||||
* @param len The length of the parameter to write
|
||||
* @param buf Pointer to data to be written
|
||||
* @returns The read length of the id is returned. If the read fails 0 is returned
|
||||
*/
|
||||
cb_uint32 cbOTP_read(cbOTP_Id id, cb_uint32 len, cb_uint8 *buf);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -0,0 +1,130 @@
|
|||
/*---------------------------------------------------------------------------
|
||||
* Copyright (c) 2016, u-blox Malmö, All Rights Reserved
|
||||
* SPDX-License-Identifier: LicenseRef-PBL
|
||||
*
|
||||
* This file and the related binary are licensed under the
|
||||
* Permissive Binary License, Version 1.0 (the "License");
|
||||
* you may not use these files except in compliance with the License.
|
||||
*
|
||||
* You may obtain a copy of the License here:
|
||||
* LICENSE-permissive-binary-license-1.0.txt and at
|
||||
* https://www.mbed.com/licenses/PBL-1.0
|
||||
*
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* Component : Wireless LAN driver
|
||||
* File : cb_types.h
|
||||
*
|
||||
* Description : Common definitions for a GCC compatible compiler.
|
||||
*-------------------------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
* @file cb_types.h Defines type required for the entire driver.
|
||||
* The defines in this file will have to be adapted for the platform.
|
||||
* @ingroup platform
|
||||
*/
|
||||
|
||||
#ifndef _CB_PLATFORM_BASIC_TYPES_H_
|
||||
#define _CB_PLATFORM_BASIC_TYPES_H_
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
/*===========================================================================
|
||||
* TYPES
|
||||
*=========================================================================*/
|
||||
|
||||
/*===========================================================================
|
||||
* COMMON SYSTEM DEFINES
|
||||
*=========================================================================*/
|
||||
|
||||
typedef int8_t cb_int8;
|
||||
typedef int16_t cb_int16;
|
||||
typedef int32_t cb_int32;
|
||||
typedef int64_t cb_int64;
|
||||
|
||||
typedef uint8_t cb_uint8;
|
||||
typedef uint16_t cb_uint16;
|
||||
typedef uint32_t cb_uint32;
|
||||
typedef uint64_t cb_uint64;
|
||||
|
||||
typedef bool cb_boolean;
|
||||
typedef char cb_char;
|
||||
typedef int cb_int;
|
||||
|
||||
/**
|
||||
* Used when declaring an empty array that does not take up space in a struct.
|
||||
* Example: struct { cb_uint8 payload[cb_EMPTY_ARRAY]; }
|
||||
* In some compilers this is empty i.e. payload[]. While in some it requires a zero.
|
||||
* I.e. payload[0];
|
||||
* Use this define to get it working for your system.
|
||||
*/
|
||||
#define cb_EMPTY_ARRAY (0)
|
||||
|
||||
/*===========================================================================
|
||||
* DEFINES
|
||||
*=========================================================================*/
|
||||
|
||||
/**
|
||||
* Used in function definitions to declare an input parameter unused to avoid warnings.
|
||||
*/
|
||||
#if defined(__GNUC__) || defined(__clang__) || defined(__CC_ARM)
|
||||
#define cb_UNUSED(x) UNUSED_ ## x __attribute__((unused))
|
||||
#else
|
||||
#define cb_UNUSED(x) UNUSED_ ## x
|
||||
#endif
|
||||
|
||||
|
||||
/**
|
||||
* Define cb_ASSERT to the wanted assert handler.
|
||||
*/
|
||||
/*
|
||||
#define cb_ASSERT(exp) do { if (!(exp)) { \
|
||||
W_PRINT("ASSERT %s:%d\n", __FILE__, __LINE__); \
|
||||
while(1); \
|
||||
} } while(0)
|
||||
*/
|
||||
#include "cb_assert.h"
|
||||
|
||||
|
||||
/**@{*/
|
||||
/**
|
||||
* Packed struct defines.
|
||||
* - cb_PACKED_STRUCT_ATTR_PRE is used before the typedef'ed struct declaration.
|
||||
* - cb_PACKED_STRUCT_ATTR_INLINE_PRE is after the typedef but before the struct declaration.
|
||||
* - cb_PACKED_STRUCT_ATTR_INLINE_POST is used after the struct declaration but before the typedef'ed name.
|
||||
* - cb_PACKED_STRUCT_ATTR_POST is used after the entire struct declaration.
|
||||
*
|
||||
* example:
|
||||
* cb_PACKED_STRUCT_ATTR_PRE
|
||||
* typedef cb_PACKED_STRUCT_ATTR_INLINE_PRE struct myPackedStruct {
|
||||
* int a;
|
||||
* int b;
|
||||
* } cb_PACKED_STRUCT_ATTR_INLINE_POST myPackedStruct
|
||||
* cb_PACKED_STRUCT_ATTR_POST
|
||||
*
|
||||
*/
|
||||
|
||||
#define cb_PACKED_STRUCT_ATTR_PRE
|
||||
|
||||
#if defined(__ICCARM__)
|
||||
#define cb_PACKED_STRUCT_ATTR_INLINE_PRE __packed
|
||||
#else
|
||||
#define cb_PACKED_STRUCT_ATTR_INLINE_PRE
|
||||
#endif
|
||||
|
||||
#if defined(__ICCARM__)
|
||||
#define cb_PACKED_STRUCT_ATTR_INLINE_POST __packed
|
||||
#else
|
||||
#define cb_PACKED_STRUCT_ATTR_INLINE_POST __attribute__ ((__packed__))
|
||||
#endif
|
||||
|
||||
|
||||
#define cb_PACKED_STRUCT_ATTR_POST
|
||||
|
||||
/**@}*/
|
||||
|
||||
|
||||
#endif /* _CB_PLATFORM_BASIC_TYPES_H_ */
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
/*---------------------------------------------------------------------------
|
||||
* Copyright (c) 2016, u-blox Malmö, All Rights Reserved
|
||||
* SPDX-License-Identifier: LicenseRef-PBL
|
||||
*
|
||||
* This file and the related binary are licensed under the
|
||||
* Permissive Binary License, Version 1.0 (the "License");
|
||||
* you may not use these files except in compliance with the License.
|
||||
*
|
||||
* You may obtain a copy of the License here:
|
||||
* LICENSE-permissive-binary-license-1.0.txt and at
|
||||
* https://www.mbed.com/licenses/PBL-1.0
|
||||
*
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* Component : Wireless LAN driver
|
||||
* File : cb_types.h
|
||||
*
|
||||
* Description : Common definitions for a GCC compatible compiler.
|
||||
*-------------------------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
* @file cb_types.h Defines type required for the entire driver.
|
||||
* The defines in this file will have to be adapted for the platform.
|
||||
* @ingroup platform
|
||||
*/
|
||||
|
||||
#ifndef _CB_PORT_TYPES_H_
|
||||
#define _CB_PORT_TYPES_H_
|
||||
|
||||
#include <cb_comdefs.h>
|
||||
|
||||
|
||||
#endif /* _CB_PORT_TYPES_H_ */
|
||||
|
|
@ -0,0 +1,44 @@
|
|||
/*---------------------------------------------------------------------------
|
||||
* Copyright (c) 2016, u-blox Malmö, All Rights Reserved
|
||||
* SPDX-License-Identifier: LicenseRef-PBL
|
||||
*
|
||||
* This file and the related binary are licensed under the
|
||||
* Permissive Binary License, Version 1.0 (the "License");
|
||||
* you may not use these files except in compliance with the License.
|
||||
*
|
||||
* You may obtain a copy of the License here:
|
||||
* LICENSE-permissive-binary-license-1.0.txt and at
|
||||
* https://www.mbed.com/licenses/PBL-1.0
|
||||
*
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* Component : RTSL
|
||||
* File : cb_status.h
|
||||
*
|
||||
* Description : Common RTSL status codes
|
||||
*-------------------------------------------------------------------------*/
|
||||
#ifndef _CB_STATUS_H_
|
||||
#define _CB_STATUS_H_
|
||||
|
||||
/*===========================================================================
|
||||
* DEFINES
|
||||
*=========================================================================*/
|
||||
|
||||
#define OK(status) (status == cbSTATUS_OK)
|
||||
|
||||
/*===========================================================================
|
||||
* TYPES
|
||||
*=========================================================================*/
|
||||
|
||||
typedef enum
|
||||
{
|
||||
cbSTATUS_OK,
|
||||
cbSTATUS_ERROR,
|
||||
cbSTATUS_BUSY,
|
||||
cbSTATUS_TIMEOUT
|
||||
|
||||
} cbRTSL_Status;
|
||||
|
||||
#endif /* _CB_STATUS_H_ */
|
||||
|
|
@ -0,0 +1,287 @@
|
|||
/*---------------------------------------------------------------------------
|
||||
* Copyright (c) 2016, u-blox Malmö, All Rights Reserved
|
||||
* SPDX-License-Identifier: LicenseRef-PBL
|
||||
*
|
||||
* This file and the related binary are licensed under the
|
||||
* Permissive Binary License, Version 1.0 (the "License");
|
||||
* you may not use these files except in compliance with the License.
|
||||
*
|
||||
* You may obtain a copy of the License here:
|
||||
* LICENSE-permissive-binary-license-1.0.txt and at
|
||||
* https://www.mbed.com/licenses/PBL-1.0
|
||||
*
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* Component : RTSL
|
||||
* File : cb_types.h
|
||||
*
|
||||
* Description : Common type definitions
|
||||
*-------------------------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
* @file cb_types.h Defines type required for the entire driver.
|
||||
* The defines in this file will have to be adapted for the platform.
|
||||
* @ingroup platform
|
||||
*/
|
||||
|
||||
#ifndef _CB_TYPES_H_
|
||||
#define _CB_TYPES_H_
|
||||
|
||||
#include "cb_port_types.h"
|
||||
|
||||
/*===========================================================================
|
||||
* TYPES
|
||||
*=========================================================================*/
|
||||
|
||||
/*===========================================================================
|
||||
* COMMON SYSTEM DEFINES
|
||||
*=========================================================================*/
|
||||
|
||||
#ifndef FALSE
|
||||
# define FALSE (0)
|
||||
#endif
|
||||
#ifndef TRUE
|
||||
# define TRUE (!FALSE)
|
||||
#endif
|
||||
|
||||
#ifndef NULL
|
||||
# define NULL ((void *) 0)
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Returns the maximum value of the two parameters.
|
||||
*/
|
||||
#ifndef cb_MAX
|
||||
# define cb_MAX(x , y) (((x) > (y)) ? (x) : (y))
|
||||
#endif
|
||||
/**
|
||||
* Returns the minimum value of the two parameters.
|
||||
*/
|
||||
#ifndef cb_MIN
|
||||
# define cb_MIN(x , y) (((x) < (y)) ? (x) : (y))
|
||||
#endif
|
||||
|
||||
#ifndef ELEMENTS_OF
|
||||
# define ELEMENTS_OF(_array) (sizeof((_array)) / sizeof((_array)[0]))
|
||||
#endif
|
||||
|
||||
#define cbWM_ARRAY_SIZE(a) ELEMENTS_OF(a)
|
||||
|
||||
/**
|
||||
* Used when declaring an empty array that does not take up space in a struct.
|
||||
* Example: struct { cb_uint8 payload[cb_EMPTY_ARRAY]; }
|
||||
* In some compilers this is empty i.e. payload[]. While in some it requires a zero.
|
||||
* I.e. payload[0];
|
||||
* Use this define to get it working for your system.
|
||||
*/
|
||||
#ifndef cb_EMPTY_ARRAY
|
||||
# define cb_EMPTY_ARRAY (0)
|
||||
#endif
|
||||
|
||||
/*===========================================================================
|
||||
* DEFINES
|
||||
*=========================================================================*/
|
||||
/**
|
||||
* Used in function definitions to declare an inparameter unused to avoid warnings.
|
||||
*/
|
||||
#ifndef cb_UNUSED
|
||||
# define cb_UNUSED(x) x
|
||||
#endif
|
||||
|
||||
#ifndef cb_ASSERT
|
||||
# error "No port definition for ASSERT!"
|
||||
#endif
|
||||
|
||||
#ifndef cb_ARG_POINTER_CHECK
|
||||
# define cb_ARG_POINTER_CHECK(ptr) if((ptr) == NULL) {cb_ASSERT(FALSE); return;}
|
||||
#endif
|
||||
#ifndef cb_ARG_POINTER_CHECK_RETURN
|
||||
# define cb_ARG_POINTER_CHECK_RETURN(ptr, returnValue) if((ptr) == NULL) {cb_ASSERT(FALSE); return (returnValue);}
|
||||
#endif
|
||||
|
||||
#ifndef cb_BIT_0
|
||||
#define cb_BIT_0 (1ul)
|
||||
#endif
|
||||
#ifndef cb_BIT_1
|
||||
#define cb_BIT_1 (1ul << 1)
|
||||
#endif
|
||||
#ifndef cb_BIT_2
|
||||
#define cb_BIT_2 (1ul << 2)
|
||||
#endif
|
||||
#ifndef cb_BIT_3
|
||||
#define cb_BIT_3 (1ul << 3)
|
||||
#endif
|
||||
#ifndef cb_BIT_4
|
||||
#define cb_BIT_4 (1ul << 4)
|
||||
#endif
|
||||
#ifndef cb_BIT_5
|
||||
#define cb_BIT_5 (1ul << 5)
|
||||
#endif
|
||||
#ifndef cb_BIT_6
|
||||
#define cb_BIT_6 (1ul << 6)
|
||||
#endif
|
||||
#ifndef cb_BIT_7
|
||||
#define cb_BIT_7 (1ul << 7)
|
||||
#endif
|
||||
#ifndef cb_BIT_8
|
||||
#define cb_BIT_8 (1ul << 8)
|
||||
#endif
|
||||
#ifndef cb_BIT_9
|
||||
#define cb_BIT_9 (1ul << 9)
|
||||
#endif
|
||||
#ifndef cb_BIT_10
|
||||
#define cb_BIT_10 (1ul << 10)
|
||||
#endif
|
||||
#ifndef cb_BIT_11
|
||||
#define cb_BIT_11 (1ul << 11)
|
||||
#endif
|
||||
#ifndef cb_BIT_12
|
||||
#define cb_BIT_12 (1ul << 12)
|
||||
#endif
|
||||
#ifndef cb_BIT_13
|
||||
#define cb_BIT_13 (1ul << 13)
|
||||
#endif
|
||||
#ifndef cb_BIT_14
|
||||
#define cb_BIT_14 (1ul << 14)
|
||||
#endif
|
||||
#ifndef cb_BIT_15
|
||||
#define cb_BIT_15 (1ul << 15)
|
||||
#endif
|
||||
#ifndef cb_BIT_16
|
||||
#define cb_BIT_16 (1ul << 16)
|
||||
#endif
|
||||
#ifndef cb_BIT_17
|
||||
#define cb_BIT_17 (1ul << 17)
|
||||
#endif
|
||||
#ifndef cb_BIT_18
|
||||
#define cb_BIT_18 (1ul << 18)
|
||||
#endif
|
||||
#ifndef cb_BIT_19
|
||||
#define cb_BIT_19 (1ul << 19)
|
||||
#endif
|
||||
#ifndef cb_BIT_20
|
||||
#define cb_BIT_20 (1ul << 20)
|
||||
#endif
|
||||
#ifndef cb_BIT_21
|
||||
#define cb_BIT_21 (1ul << 21)
|
||||
#endif
|
||||
#ifndef cb_BIT_22
|
||||
#define cb_BIT_22 (1ul << 22)
|
||||
#endif
|
||||
#ifndef cb_BIT_23
|
||||
#define cb_BIT_23 (1ul << 23)
|
||||
#endif
|
||||
#ifndef cb_BIT_24
|
||||
#define cb_BIT_24 (1ul << 24)
|
||||
#endif
|
||||
#ifndef cb_BIT_25
|
||||
#define cb_BIT_25 (1ul << 25)
|
||||
#endif
|
||||
#ifndef cb_BIT_26
|
||||
#define cb_BIT_26 (1ul << 26)
|
||||
#endif
|
||||
#ifndef cb_BIT_27
|
||||
#define cb_BIT_27 (1ul << 27)
|
||||
#endif
|
||||
#ifndef cb_BIT_28
|
||||
#define cb_BIT_28 (1ul << 28)
|
||||
#endif
|
||||
#ifndef cb_BIT_29
|
||||
#define cb_BIT_29 (1ul << 29)
|
||||
#endif
|
||||
#ifndef cb_BIT_30
|
||||
#define cb_BIT_30 (1ul << 30)
|
||||
#endif
|
||||
#ifndef cb_BIT_31
|
||||
#define cb_BIT_31 (1ul << 31)
|
||||
#endif
|
||||
|
||||
#ifndef cb_UINT8_MAX
|
||||
#define cb_UINT8_MAX ((cb_uint8)0xff)
|
||||
#endif
|
||||
#ifndef cb_UINT16_MAX
|
||||
#define cb_UINT16_MAX ((cb_uint16)0xffff)
|
||||
#endif
|
||||
#ifndef cb_UINT32_MAX
|
||||
#define cb_UINT32_MAX ((cb_uint32)0xffffffff)
|
||||
#endif
|
||||
#ifndef cb_INT8_MAX
|
||||
#define cb_INT8_MAX ((cb_uint8)0x7f)
|
||||
#endif
|
||||
#ifndef cb_INT16_MAX
|
||||
#define cb_INT16_MAX ((cb_uint16)0x7fff)
|
||||
#endif
|
||||
#ifndef cb_INT32_MAX
|
||||
#define cb_INT32_MAX ((cb_uint32)0x7fffffff)
|
||||
#endif
|
||||
#ifndef cb_INT8_MIN
|
||||
#define cb_INT8_MIN ((cb_uint8)0x80)
|
||||
#endif
|
||||
#ifndef cb_INT16_MIN
|
||||
#define cb_INT16_MIN ((cb_uint16)0x8000)
|
||||
#endif
|
||||
#ifndef cb_INT32_MIN
|
||||
#define cb_INT32_MIN ((cb_uint32)0x80000000)
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Clears (set to zero) a bit or bits in a variable.
|
||||
* @param variable The variable.
|
||||
* @param bit The bit or bits to clear
|
||||
*/
|
||||
#ifndef cb_CLEAR_BIT
|
||||
# define cb_CLEAR_BIT(variable,bit) ((variable) &= ~((bit)))
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Gets a bit i.e. checks if it is set in a variable.
|
||||
*
|
||||
* Also works to see if any of several bits are set.
|
||||
*
|
||||
* @param variable The variable.
|
||||
* @param bit The bit to check if it set.
|
||||
* @return @ref TRUE if any of the bits are set, @ref FALSE otherwise.
|
||||
*/
|
||||
#ifndef cb_GET_BIT
|
||||
# define cb_GET_BIT(variable,bit) (((variable) & ((bit))) ? TRUE : FALSE)
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Sets (set to 1) a bit or bits in a variable.
|
||||
*
|
||||
* @param variable The variable.
|
||||
* @param bit The bit or bits to set in the variable.
|
||||
*/
|
||||
#ifndef cb_SET_BIT
|
||||
# define cb_SET_BIT(variable,bit) ((variable) |= (bit))
|
||||
#endif
|
||||
|
||||
|
||||
/*Packed struct defines*/
|
||||
#ifndef cb_PACKED_STRUCT_ATTR_INLINE_POST
|
||||
# define cb_PACKED_STRUCT_ATTR_INLINE_POST
|
||||
#endif
|
||||
#ifndef cb_PACKED_STRUCT_ATTR_INLINE_PRE
|
||||
# define cb_PACKED_STRUCT_ATTR_INLINE_PRE
|
||||
#endif
|
||||
#ifndef cb_PACKED_STRUCT_ATTR_PRE
|
||||
# define cb_PACKED_STRUCT_ATTR_PRE
|
||||
#endif
|
||||
#ifndef cb_PACKED_STRUCT_ATTR_POST
|
||||
# define cb_PACKED_STRUCT_ATTR_POST
|
||||
#endif
|
||||
|
||||
#ifndef cb_PACKED_STRUCT_BEGIN
|
||||
# define cb_PACKED_STRUCT_BEGIN(name) \
|
||||
cb_PACKED_STRUCT_ATTR_PRE \
|
||||
typedef cb_PACKED_STRUCT_ATTR_INLINE_PRE struct name##_t
|
||||
#endif
|
||||
|
||||
#ifndef cb_PACKED_STRUCT_END
|
||||
# define cb_PACKED_STRUCT_END(name) \
|
||||
cb_PACKED_STRUCT_ATTR_INLINE_POST name; \
|
||||
cb_PACKED_STRUCT_ATTR_POST
|
||||
#endif
|
||||
|
||||
#endif /* _CB_TYPES_H_ */
|
|
@ -0,0 +1,71 @@
|
|||
/*---------------------------------------------------------------------------
|
||||
* Copyright (c) 2016, u-blox Malmö, All Rights Reserved
|
||||
* SPDX-License-Identifier: LicenseRef-PBL
|
||||
*
|
||||
* This file and the related binary are licensed under the
|
||||
* Permissive Binary License, Version 1.0 (the "License");
|
||||
* you may not use these files except in compliance with the License.
|
||||
*
|
||||
* You may obtain a copy of the License here:
|
||||
* LICENSE-permissive-binary-license-1.0.txt and at
|
||||
* https://www.mbed.com/licenses/PBL-1.0
|
||||
*
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* Component: Watchdog
|
||||
* File: cb_watchdog.h
|
||||
*
|
||||
* Description: Functionality for watchdog and reset.
|
||||
*-------------------------------------------------------------------------*/
|
||||
#ifndef _CB_WATCHDOG_H_
|
||||
#define _CB_WATCHDOG_H_
|
||||
|
||||
#include "cb_comdefs.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*===========================================================================
|
||||
* DEFINES
|
||||
*=========================================================================*/
|
||||
|
||||
/*===========================================================================
|
||||
* TYPES
|
||||
*=========================================================================*/
|
||||
|
||||
|
||||
/*===========================================================================
|
||||
* FUNCTIONS
|
||||
*=========================================================================*/
|
||||
|
||||
/**
|
||||
* Put watchdog in a defined state.
|
||||
*/
|
||||
void cbWD_init(void);
|
||||
|
||||
/**
|
||||
* Resets the CPU.
|
||||
*/
|
||||
void cbWD_systemReset(void);
|
||||
|
||||
/**
|
||||
* Enables watchdog. Watchdog needs to be polled using cbWD_poll() with
|
||||
* shorter intervals then specified by timeInMilliseconds.
|
||||
*
|
||||
* @param timeInMilliseconds Watchdog timeout in milliseconds.
|
||||
*/
|
||||
void cbWD_enable(cb_uint32 timeInMilliseconds);
|
||||
|
||||
/**
|
||||
* Poll the watchdog timer. This must be done with shorter intervalls
|
||||
* than the time in cbWD_enable().
|
||||
*/
|
||||
void cbWD_poll(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _CB_WATCHDOG_H_ */
|
|
@ -0,0 +1,567 @@
|
|||
/*---------------------------------------------------------------------------
|
||||
* Copyright (c) 2016, u-blox Malmö, All Rights Reserved
|
||||
* SPDX-License-Identifier: LicenseRef-PBL
|
||||
*
|
||||
* This file and the related binary are licensed under the
|
||||
* Permissive Binary License, Version 1.0 (the "License");
|
||||
* you may not use these files except in compliance with the License.
|
||||
*
|
||||
* You may obtain a copy of the License here:
|
||||
* LICENSE-permissive-binary-license-1.0.txt and at
|
||||
* https://www.mbed.com/licenses/PBL-1.0
|
||||
*
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* Component : WLAN
|
||||
* File : cb_wlan.h
|
||||
*
|
||||
* Description : Main WLAN component, ties together WM, SUPPLICANT and
|
||||
* TARGET to one streamlined API.
|
||||
*-------------------------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
* @file cb_wlan.h The main WLAN component interface.
|
||||
* All functions declared extern needs to be provided by another/upper layer.
|
||||
* @ingroup wlan
|
||||
*/
|
||||
|
||||
#ifndef _CB_WLAN_H_
|
||||
#define _CB_WLAN_H_
|
||||
|
||||
#include "cb_types.h"
|
||||
#include "cb_wlan_types.h"
|
||||
#include "cb_status.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/*===========================================================================
|
||||
* DEFINES
|
||||
*=========================================================================*/
|
||||
|
||||
/**
|
||||
* Max username length in @ref cbWLAN_EnterpriseConnectParameters
|
||||
*
|
||||
* @ingroup wlan
|
||||
*/
|
||||
#define cbWLAN_MAX_USERNAME_LENGTH 64
|
||||
|
||||
/**
|
||||
* Max password length in @ref cbWLAN_Util_PSKFromPWD and @ref cbWLAN_EnterpriseConnectParameters
|
||||
*
|
||||
* @ingroup wlan
|
||||
*/
|
||||
#define cbWLAN_MAX_PASSPHRASE_LENGTH 64
|
||||
|
||||
/**
|
||||
* PSK length in @ref cbWLAN_WPAPSKConnectParameters
|
||||
*
|
||||
* @ingroup wlan
|
||||
*/
|
||||
#define cbWLAN_PSK_LENGTH 32
|
||||
|
||||
|
||||
/**
|
||||
* Max domain name length in @ref cbWLAN_EnterpriseConnectParameters
|
||||
*
|
||||
* @ingroup wlan
|
||||
*/
|
||||
#define cbWLAN_MAX_DOMAIN_LENGTH 64
|
||||
|
||||
|
||||
/*===========================================================================
|
||||
* TYPES
|
||||
*=========================================================================*/
|
||||
|
||||
typedef struct cbWLAN_Stream_s cbWLAN_Stream;
|
||||
typedef cb_uint32 cbWLAN_StreamPosition;
|
||||
|
||||
/**
|
||||
* Stream vtable interface used by WLAN supplicant to access SSL certificates
|
||||
* for WPA Enterprise authentication.
|
||||
*
|
||||
* @ingroup wlan
|
||||
*/
|
||||
struct cbWLAN_Stream_s {
|
||||
cb_int32 (*read)(const cbWLAN_Stream *stream, void *buf, cb_uint32 count); /**< Read function pointer, place count bytes in buf. */
|
||||
cb_int32 (*write)(const cbWLAN_Stream *stream, void *buf, cb_uint32 count); /**< Read function pointer, place count bytes in buf. */
|
||||
void (*rewind)(const cbWLAN_Stream *stream); /**< Rewind function pointer, rewind stream internal iterator to the beginning. Mandatory for all streams. */
|
||||
void (*setPosition)(const cbWLAN_Stream *stream, cbWLAN_StreamPosition position); /**< Set absolute position. */
|
||||
cbWLAN_StreamPosition (*getPosition)(const cbWLAN_Stream *stream); /**< Get current position. */
|
||||
cb_uint32 (*getSize)(const cbWLAN_Stream *stream); /**< GetSize function pointer, return total size of stream contents. */
|
||||
};
|
||||
|
||||
/**
|
||||
* Start parameters passed to WLAN driver.
|
||||
*
|
||||
* @ingroup wlan
|
||||
*/
|
||||
typedef struct cbWLAN_StartParameters {
|
||||
cbWLAN_MACAddress mac; /**< MAC of WLAN interface, set to all zeros if hardware programmed address should be used. */
|
||||
cb_boolean disable80211d;
|
||||
cbWM_ModuleType deviceType; /**< Specify current device type. */
|
||||
union {
|
||||
struct {
|
||||
cbWM_TxPowerSettings txPowerSettings; /**< Transmission power settings. */
|
||||
} ODIN_W26X;
|
||||
} deviceSpecific;
|
||||
} cbWLAN_StartParameters;
|
||||
|
||||
/**
|
||||
* Common connect parameters.
|
||||
*
|
||||
* @ingroup wlan
|
||||
*/
|
||||
typedef struct cbWLAN_CommonConnectParameters {
|
||||
cbWLAN_MACAddress bssid; /**< BSSID to connect to, set to all zero for any BSSID. */
|
||||
cbWLAN_Ssid ssid; /**< SSID to connect to. */
|
||||
} cbWLAN_CommonConnectParameters;
|
||||
|
||||
|
||||
/**
|
||||
* WEP specific connect parameters.
|
||||
*
|
||||
* @ingroup wlan
|
||||
*/
|
||||
typedef struct cbWLAN_WEPConnectParameters {
|
||||
cbWLAN_WEPKey keys[4]; /**< WEP keys. */
|
||||
cb_uint32 txKey; /**< Active WEP transmission key index (0-3). */
|
||||
} cbWLAN_WEPConnectParameters;
|
||||
|
||||
/**
|
||||
* WPA PSK parameters.
|
||||
*
|
||||
* @ingroup wlan
|
||||
*/
|
||||
typedef struct cbWLAN_WPAPSK {
|
||||
cb_uint8 key[cbWLAN_PSK_LENGTH]; /**< WPA pre-shared key in binary form. */
|
||||
} cbWLAN_WPAPSK;
|
||||
|
||||
/**
|
||||
* WPA PSK specific connect parameters.
|
||||
*
|
||||
* @ingroup wlan
|
||||
*/
|
||||
typedef struct cbWLAN_WPAPSKConnectParameters {
|
||||
cbWLAN_WPAPSK psk; /**< WPA pre-shared key*/
|
||||
} cbWLAN_WPAPSKConnectParameters;
|
||||
|
||||
|
||||
typedef enum cbWLAN_CipherSuite {
|
||||
cbWLAN_CIPHER_SUITE_NONE = 0x00,
|
||||
cbWLAN_CIPHER_SUITE_WEP64 = 0x01,
|
||||
cbWLAN_CIPHER_SUITE_WEP128 = 0x02,
|
||||
cbWLAN_CIPHER_SUITE_TKIP = 0x04,
|
||||
cbWLAN_CIPHER_SUITE_AES_CCMP = 0x08,
|
||||
} cbWLAN_CipherSuite;
|
||||
|
||||
typedef enum cbWLAN_AuthenticationSuite {
|
||||
cbWLAN_AUTHENTICATION_SUITE_NONE = 0x00,
|
||||
cbWLAN_AUTHENTICATION_SUITE_SHARED_SECRET = 0x01,
|
||||
cbWLAN_AUTHENTICATION_SUITE_PSK = 0x02,
|
||||
cbWLAN_AUTHENTICATION_SUITE_8021X = 0x04,
|
||||
cbWLAN_AUTHENTICATION_SUITE_USE_WPA = 0x08,
|
||||
cbWLAN_AUTHENTICATION_SUITE_USE_WPA2 = 0x10,
|
||||
} cbWLAN_AuthenticationSuite;
|
||||
|
||||
|
||||
/**
|
||||
* WPA Enterprise specific connect parameters.
|
||||
*
|
||||
* @ingroup wlan
|
||||
*/
|
||||
typedef struct cbWLAN_EnterpriseConnectParameters {
|
||||
cbWLAN_EnterpriseMode authMode; /**< Enterprise authentication mode. */
|
||||
cb_uint8 username[cbWLAN_MAX_USERNAME_LENGTH]; /**< Username string. */
|
||||
cb_uint8 passphrase[cbWLAN_MAX_PASSPHRASE_LENGTH]; /**< Passphrase string. */
|
||||
cb_uint8 domain[cbWLAN_MAX_DOMAIN_LENGTH]; /**< Domain string. */
|
||||
cbWLAN_Stream *clientCertificate; /**< Stream handle to provide SSL certificate for authentication. */
|
||||
cbWLAN_Stream *clientPrivateKey; /**< STream handle to provide SSL private key for authentication. */
|
||||
} cbWLAN_EnterpriseConnectParameters;
|
||||
|
||||
/**
|
||||
* Common access point parameters.
|
||||
*
|
||||
* @ingroup wlan
|
||||
*/
|
||||
typedef struct cbWLAN_CommonApParameters {
|
||||
cbWLAN_Ssid ssid; /**< SSID to connect to. */
|
||||
cbWLAN_Channel channel; /**< Active channel. */
|
||||
cbWLAN_RateMask basicRates; /**< Basic rates. */
|
||||
}cbWLAN_CommonApParameters;
|
||||
|
||||
|
||||
/**
|
||||
* WPA PSK specific AP parameters.
|
||||
*
|
||||
* @ingroup wlan
|
||||
*/
|
||||
typedef struct cbWLAN_WPAPSKApParameters {
|
||||
cbWLAN_CipherSuite rsnCiphers; /**< Bit field indicating which ciphers that shall be displayed in RSN information elements. If 0 no RSN information elements is added to beacons and probe responses. */
|
||||
cbWLAN_CipherSuite wpaCiphers; /**< Bit field indicating which ciphers that shall be displayed in WPA information elements. If 0 no WPA information elements is added to beacons and probe responses. */
|
||||
cbWLAN_WPAPSK psk; /**< WPA pre-shared key*/
|
||||
} cbWLAN_WPAPSKApParameters;
|
||||
|
||||
|
||||
/**
|
||||
* Scan parameters
|
||||
*
|
||||
* @ingroup wlan
|
||||
*/
|
||||
typedef struct cbWLAN_ScanParameters {
|
||||
cbWLAN_Ssid ssid; /**< SSID to scan for, set to zero length for broadcast scan. */
|
||||
} cbWLAN_ScanParameters;
|
||||
|
||||
/**
|
||||
* Scan result information reported from WLAN component. Contains info for
|
||||
* one specific BSS.
|
||||
*
|
||||
* @ingroup wlan
|
||||
*/
|
||||
typedef struct cbWLAN_ScanIndicationInfo {
|
||||
cbWLAN_MACAddress bssid; /**< BSS BSSID */
|
||||
cbWLAN_Ssid ssid; /**< BSS SSID */
|
||||
cbWLAN_Channel channel; /**< BSS channel */
|
||||
cbWLAN_OperationalMode operationalMode; /**< BSS type */
|
||||
cb_int32 rssi; /**< RSSI for scan result packet. */
|
||||
|
||||
cbWLAN_AuthenticationSuite authenticationSuites; /**< Supported authentication suites */
|
||||
cbWLAN_CipherSuite unicastCiphers; /**< Supported unicast cipher suites */
|
||||
cbWLAN_CipherSuite groupCipher; /**< Supported group cipher suites */
|
||||
|
||||
cbWLAN_RateMask basicRateSet; /**< Basic rate set, i.e. required rates. */
|
||||
cbWLAN_RateMask supportedRateSet; /**< Supported rate set, super set of basic rate set. */
|
||||
cb_uint32 beaconPeriod; /**< Beacon period in ms. */
|
||||
cb_uint32 DTIMPeriod; /**< DTIM period in beacon intervals */
|
||||
cb_uint8 countryCode[3]; /**< Three letter country code */
|
||||
cb_uint32 flags; // QoS, short preamble, DFS, privacy,
|
||||
} cbWLAN_ScanIndicationInfo;
|
||||
|
||||
/**
|
||||
* Status indications indicated by @ref cbWLAN_statusIndication.
|
||||
*
|
||||
* @ingroup wlan
|
||||
*/
|
||||
typedef enum {
|
||||
cbWLAN_STATUS_STOPPED,
|
||||
cbWLAN_STATUS_STARTED,
|
||||
cbWLAN_STATUS_ERROR,
|
||||
cbWLAN_STATUS_DISCONNECTED,
|
||||
cbWLAN_STATUS_CONNECTING,
|
||||
cbWLAN_STATUS_CONNECTED,
|
||||
cbWLAN_STATUS_CONNECTION_FAILURE,
|
||||
cbWLAN_STATUS_AP_UP,
|
||||
cbWLAN_STATUS_AP_DOWN,
|
||||
cbWLAN_STATUS_AP_STA_ADDED,
|
||||
cbWLAN_STATUS_AP_STA_REMOVED,
|
||||
} cbWLAN_StatusIndicationInfo;
|
||||
|
||||
/**
|
||||
* Disconnection reasons for @ref cbWLAN_STATUS_DISCONNECTED.
|
||||
*
|
||||
* @ingroup wlan
|
||||
*/
|
||||
typedef enum {
|
||||
cbWLAN_STATUS_DISCONNECTED_UNKNOWN,
|
||||
cbWLAN_STATUS_DISCONNECTED_NO_BSSID_FOUND,
|
||||
cbWLAN_STATUS_DISCONNECTED_AUTH_TIMEOUT,
|
||||
cbWLAN_STATUS_DISCONNECTED_MIC_FAILURE,
|
||||
} cbWLAN_StatusDisconnectedInfo;
|
||||
|
||||
/**
|
||||
* IOCTL parameters @ref cbWLAN_ioctl
|
||||
*
|
||||
* @ingroup wlan
|
||||
*/
|
||||
typedef enum {
|
||||
cbWLAN_IOCTL_FIRST,
|
||||
cbWLAN_IOCTL_SET_POWER_SAVE_MODE = cbWLAN_IOCTL_FIRST, //!< Set power mode @ref cbWLAN_IoctlPowerSaveMode
|
||||
cbWLAN_IOCTL_GET_POWER_SAVE_MODE, //!< Get power mode @ref cbWLAN_IoctlPowerSaveMode
|
||||
cbWLAN_IOCTL_SET_LISTEN_INTERVAL, //!< Set listen interval, integer value 0 - 16
|
||||
cbWLAN_IOCTL_GET_LISTEN_INTERVAL, //!< Get listen interval, integer value 0 - 16
|
||||
cbWLAN_IOCTL_SET_DTIM_ENABLE, //!< Set DTIM enable 0, disable 1 enable
|
||||
cbWLAN_IOCTL_GET_DTIM_ENABLE, //!< Get DTIM enable 0, disable 1 enable
|
||||
cbWLAN_IOCTL_SET_SLEEP_TIMEOUT, //!< Set enter power save entry delay (in ms). Power save mode will be entered only if there no activity during this delay
|
||||
cbWLAN_IOCTL_GET_SLEEP_TIMEOUT, //!< Get enter power save entry delay (in ms). Power save mode will be entered only if there no activity during this delay
|
||||
|
||||
cbWLAN_IOCTL_LAST,
|
||||
} cbWLAN_Ioctl;
|
||||
|
||||
/**
|
||||
* Power save modes set using @ref cbWLAN_ioctl
|
||||
*
|
||||
* @ingroup wlan
|
||||
*/
|
||||
typedef enum {
|
||||
cbWLAN_IOCTL_POWER_SAVE_MODE_OFF,
|
||||
cbWLAN_IOCTL_POWER_SAVE_MODE_SLEEP,
|
||||
cbWLAN_IOCTL_POWER_SAVE_MODE_DEEP_SLEEP
|
||||
} cbWLAN_IoctlPowerSaveMode;
|
||||
|
||||
/**
|
||||
* Start parameters indicated from WLAN driver for status indication
|
||||
* @ref cbWLAN_STATUS_STARTED.
|
||||
*
|
||||
* @ingroup wlan
|
||||
*/
|
||||
typedef struct cbWLAN_StatusStartedInfo {
|
||||
cbWLAN_MACAddress macAddress; /**< MAC address of WLAN driver. */
|
||||
} cbWLAN_StatusStartedInfo;
|
||||
|
||||
/**
|
||||
* Connected parameters indicated from WLAN driver for status indication
|
||||
* @ref cbWLAN_STATUS_CONNECTED.
|
||||
*
|
||||
* @ingroup wlan
|
||||
*/
|
||||
typedef struct cbWLAN_StatusConnectedInfo {
|
||||
cbWLAN_MACAddress bssid; /**< BSSID of the BSS connected to. */
|
||||
cbWLAN_Channel channel; /**< Operating channels of the BSS connected to. */
|
||||
} cbWLAN_StatusConnectedInfo;
|
||||
|
||||
/**
|
||||
* Received Ethernet data packet information and properties.
|
||||
*
|
||||
* @ingroup wlan
|
||||
*/
|
||||
typedef struct cbWLAN_PacketIndicationInfo {
|
||||
void *rxData; /**< Pointer to the port specific data type. */
|
||||
cb_uint32 size; /**< Length of the data payload in the port specific packet data type. */
|
||||
cb_boolean isChecksumVerified; /**< True if the TCP/UDP checksum is verified and correct. */
|
||||
} cbWLAN_PacketIndicationInfo;
|
||||
|
||||
/**
|
||||
* Status updates from WLAN component.
|
||||
* @note The callback must not make any call back to WLAN.
|
||||
*
|
||||
* @param callbackContext Context pointer provided in @ref cbWLAN_registerStatusCallback.
|
||||
* @param status Status indication type.
|
||||
* @param data Additional status indication data, depends on indication type.
|
||||
*
|
||||
* @sa cbWLAN_registerStatusCallback
|
||||
*/
|
||||
typedef void (*cbWLAN_statusIndication)(void *callbackContext, cbWLAN_StatusIndicationInfo status, void *data);
|
||||
|
||||
|
||||
/**
|
||||
* Indication of received Ethernet data packet.
|
||||
*
|
||||
* @param callbackContext Context pointer provided in @ref cbWLAN_init.
|
||||
* @param packetInfo Pointer to struct containing packet information and data pointers.
|
||||
*/
|
||||
typedef void (*cbWLAN_packetIndication)(void *callbackContext, cbWLAN_PacketIndicationInfo *packetInfo);
|
||||
|
||||
/**
|
||||
* Scan result indication from WLAN component.
|
||||
*
|
||||
* @param callbackContext Context pointer provided in @ref cbWLAN_init.
|
||||
* @param bssDescriptor Pointer to struct containing scan result information.
|
||||
* @param isLastResult @ref TRUE if scan scan is finished.
|
||||
*/
|
||||
typedef void (*cbWLAN_scanIndication)(void *callbackContext, cbWLAN_ScanIndicationInfo *bssDescriptor, cb_boolean isLastResult);
|
||||
|
||||
/*===========================================================================
|
||||
* WLAN API
|
||||
*=========================================================================*/
|
||||
|
||||
/**
|
||||
* Initialize WLAN component.
|
||||
*
|
||||
* @param callbackContext Context handle used in indication callbacks.
|
||||
* @return @ref cbSTATUS_OK if successful, otherwise cbSTATUS_ERROR.
|
||||
*/
|
||||
cbRTSL_Status cbWLAN_init(void *callbackContext);
|
||||
|
||||
|
||||
/**
|
||||
* Stop WLAN component.
|
||||
* Stop and destroy WLAN driver instance.
|
||||
*
|
||||
* @return @ref cbSTATUS_OK if successful, otherwise cbSTATUS_ERROR.
|
||||
*/
|
||||
cbRTSL_Status cbWLAN_stop(void);
|
||||
|
||||
/**
|
||||
* Connect to access point in open mode (no encryption).
|
||||
* Connection progress is reported as @ref cbWLAN_statusIndication callbacks.
|
||||
*
|
||||
* @param commonParams Connection parameters.
|
||||
* @return @ref cbSTATUS_OK if call successful, otherwise cbSTATUS_ERROR.
|
||||
*/
|
||||
cbRTSL_Status cbWLAN_connectOpen(cbWLAN_CommonConnectParameters *commonParams);
|
||||
|
||||
/**
|
||||
* Connect to access point in open mode with WEP encryption.
|
||||
* Connection progress is reported as @ref cbWLAN_statusIndication callbacks.
|
||||
*
|
||||
* @param commonParams Connection parameters.
|
||||
* @param wepParams WEP specific connection parameters.
|
||||
* @return @ref cbSTATUS_OK if call successful, otherwise cbSTATUS_ERROR.
|
||||
*/
|
||||
cbRTSL_Status cbWLAN_connectWEP(cbWLAN_CommonConnectParameters *commonParams, cbWLAN_WEPConnectParameters *wepParams);
|
||||
|
||||
/**
|
||||
* Connect to access point with WPA PSK authentication.
|
||||
* Connection progress is reported as @ref cbWLAN_statusIndication callbacks.
|
||||
*
|
||||
* @param commonParams Connection parameters.
|
||||
* @param wpaParams WPA PSK specific connection parameters.
|
||||
* @return @ref cbSTATUS_OK if call successful, otherwise cbSTATUS_ERROR.
|
||||
*/
|
||||
cbRTSL_Status cbWLAN_connectWPAPSK(cbWLAN_CommonConnectParameters *commonParams, cbWLAN_WPAPSKConnectParameters *wpaParams);
|
||||
|
||||
/**
|
||||
* Disconnect from access point or stop ongoing connection attempt.
|
||||
* Disconnection progress is reported as @ref cbWLAN_statusIndication callback.
|
||||
*
|
||||
* @return @ref cbSTATUS_OK if call successful, otherwise cbSTATUS_ERROR.
|
||||
*/
|
||||
cbRTSL_Status cbWLAN_disconnect(void);
|
||||
|
||||
/**
|
||||
* Initiate BSS scan.
|
||||
* If specific channel is set in scan parameters, only that channel is
|
||||
* scanned. If SSID is specified, a directed probe request against that SSID
|
||||
* will be used. Scan results are reported in @ref cbWLAN_scanIndication
|
||||
* callbacks.
|
||||
* @note Depending on channel using DFS or not, passive scans may be used
|
||||
* instead of active probe requests.
|
||||
*
|
||||
* @param params Scan parameters
|
||||
* @param scanIndication Callback function for scan results.
|
||||
* @param callbackContext Context pointer, will be sent back in callback.
|
||||
* @return @ref cbSTATUS_OK if call successful, otherwise cbSTATUS_ERROR.
|
||||
*/
|
||||
cbRTSL_Status cbWLAN_scan(cbWLAN_ScanParameters *params, cbWLAN_scanIndication scanIndication, void *callbackContext);
|
||||
|
||||
|
||||
/**
|
||||
* Retrieve an RSSI value for station mode.
|
||||
*
|
||||
* @note Depending on connection state and data transfer interval
|
||||
* the value may be incorrect.
|
||||
*
|
||||
* @return RSSI value in dBm
|
||||
*/
|
||||
cb_int16 cbWLAN_STA_getRSSI();
|
||||
|
||||
/**
|
||||
* Start access point in open mode (no encryption).
|
||||
* Connection progress is reported as @ref cbWLAN_statusIndication callbacks.
|
||||
*
|
||||
* @param commonParams Common Accesspoint parameters.
|
||||
* @return @ref cbSTATUS_OK if call successful, otherwise cbSTATUS_ERROR.
|
||||
*/
|
||||
cbRTSL_Status cbWLAN_apStartOpen(cbWLAN_CommonApParameters *commonParams);
|
||||
|
||||
/**
|
||||
* Start access point with WPA PSK authentication.
|
||||
* Connection progress is reported as @ref cbWLAN_statusIndication callbacks.
|
||||
*
|
||||
* @param commonParams Common Accesspoint parameters.
|
||||
* @param wpaParams WPA PSK specific parameters.
|
||||
* @return @ref cbSTATUS_OK if call successful, otherwise cbSTATUS_ERROR.
|
||||
*/
|
||||
cbRTSL_Status cbWLAN_apStartWPAPSK(cbWLAN_CommonApParameters *commonParams, cbWLAN_WPAPSKApParameters *wpaParams);
|
||||
|
||||
/**
|
||||
* Stop access point.
|
||||
*
|
||||
* @return @ref cbSTATUS_OK if call successful, otherwise cbSTATUS_ERROR.
|
||||
*/
|
||||
cbRTSL_Status cbWLAN_apStop(void);
|
||||
|
||||
/**
|
||||
* Send an Ethernet data packet.
|
||||
* @note Data send when not in connected state is just dropped.
|
||||
*
|
||||
* @param txData Pointer to the port specific Ethernet data type containing transmit data
|
||||
*/
|
||||
void cbWLAN_sendPacket(void *txData);
|
||||
|
||||
/**
|
||||
* Register a status indication callback.
|
||||
* @note There may be multiple clients connected.
|
||||
*
|
||||
* @param statusIndication Callback function.
|
||||
* @param callbackContext Context pointer, will be sent back in callback.
|
||||
* @return @ref cbSTATUS_OK if call successful, otherwise cbSTATUS_ERROR.
|
||||
*/
|
||||
cbRTSL_Status cbWLAN_registerStatusCallback(cbWLAN_statusIndication statusIndication, void *callbackContext);
|
||||
|
||||
|
||||
/**
|
||||
* Register a status indication callback.
|
||||
*
|
||||
* @param packetIndication Callback function.
|
||||
* @param callbackContext Context pointer, will be sent back in callback.
|
||||
* @return @ref cbSTATUS_OK if call successful, otherwise cbSTATUS_ERROR.
|
||||
*/
|
||||
cbRTSL_Status cbWLAN_registerPacketIndicationCallback(cbWLAN_packetIndication packetIndication, void *callbackContext);
|
||||
|
||||
/**
|
||||
* Deregister the specified status indication callback.
|
||||
*
|
||||
* @param statusIndication Callback function.
|
||||
* @param callbackContext Context pointer, will be sent back in callback.
|
||||
* @return @ref cbSTATUS_OK if call successful, otherwise cbSTATUS_ERROR.
|
||||
*/
|
||||
cbRTSL_Status cbWLAN_deregisterStatusCallback(cbWLAN_statusIndication statusIndication, void *callbackContext);
|
||||
|
||||
|
||||
cbRTSL_Status cbWLAN_Util_PSKFromPWD(cb_char passphrase[cbWLAN_MAX_PASSPHRASE_LENGTH], cbWLAN_Ssid ssid, cb_uint8 psk[cbWLAN_PSK_LENGTH]);
|
||||
|
||||
/**
|
||||
* Set the channel list to be used for connection and scanning.
|
||||
* The list will be filtered according to the allowed channel list
|
||||
* set. The list can include both 2.4GHz and 5GHz channels.
|
||||
* If channel list parameter is NULL the default channel list is
|
||||
* restored.
|
||||
*
|
||||
* @param channelList Pointer to channel list for the driver to use.
|
||||
*
|
||||
* @return @ref cbSTATUS_OK if call successful, otherwise cbSTATUS_ERROR.
|
||||
*/
|
||||
cbRTSL_Status cbWLAN_setChannelList(const cbWLAN_ChannelList *channelList);
|
||||
|
||||
/**
|
||||
* Returns the wanted channel list.
|
||||
*
|
||||
* @param channelList Pointer to channel list
|
||||
*
|
||||
* @return @ref cbSTATUS_OK if call successful, otherwise cbSTATUS_ERROR.
|
||||
*/
|
||||
cbRTSL_Status cbWLAN_getChannelList(cbWLAN_ChannelList *channelList);
|
||||
|
||||
/**
|
||||
* Returns the channel list currently used. This channel list
|
||||
* depend on the channel list specified by the user and the
|
||||
* current regulatory domain.
|
||||
*
|
||||
* @param channelList Pointer to channel list
|
||||
*
|
||||
* @return @ref cbSTATUS_OK if call successful, otherwise cbSTATUS_ERROR.
|
||||
*/
|
||||
cbRTSL_Status cbWLAN_getActiveChannelList(cbWLAN_ChannelList *channelList);
|
||||
|
||||
/**
|
||||
* WLAN control settings. Both in and out parameters are supported.
|
||||
* If an ioctl request is not supported cbSTATUS_ERROR is returned and
|
||||
* the value parameter shall be ignored.
|
||||
*
|
||||
* @param ioctl Parameter that shall be set. @ref cbWLAN_Ioctl lists all supported parameters.
|
||||
* @param value Value. @ref cbWLAN_Ioctl lists the type for all supported parameters.
|
||||
*
|
||||
* @return @ref cbSTATUS_OK if call successful, otherwise cbSTATUS_ERROR.
|
||||
*/
|
||||
cbRTSL_Status cbWLAN_ioctl(cbWLAN_Ioctl ioctl, void* value);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _CB_WLAN_H_ */
|
||||
|
|
@ -0,0 +1,119 @@
|
|||
/*---------------------------------------------------------------------------
|
||||
* Copyright (c) 2016, u-blox Malmö, All Rights Reserved
|
||||
* SPDX-License-Identifier: LicenseRef-PBL
|
||||
*
|
||||
* This file and the related binary are licensed under the
|
||||
* Permissive Binary License, Version 1.0 (the "License");
|
||||
* you may not use these files except in compliance with the License.
|
||||
*
|
||||
* You may obtain a copy of the License here:
|
||||
* LICENSE-permissive-binary-license-1.0.txt and at
|
||||
* https://www.mbed.com/licenses/PBL-1.0
|
||||
*
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* Component : Wireless LAN driver
|
||||
* File : cb_wlan_target_data.h
|
||||
*
|
||||
* Description : Port specific data buffer handling (ethernet frames)
|
||||
*-------------------------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
* @file cb_wlan_target_data.h Handles the anonymous port specific packetization
|
||||
* of ethernet frames.
|
||||
* @ingroup target
|
||||
*/
|
||||
|
||||
#ifndef _CB_WLANTARGET_DATA_H_
|
||||
#define _CB_WLANTARGET_DATA_H_
|
||||
|
||||
#include "cb_types.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*===========================================================================
|
||||
* DEFINES
|
||||
*=========================================================================*/
|
||||
|
||||
/*===========================================================================
|
||||
* TYPES
|
||||
*=========================================================================*/
|
||||
|
||||
typedef struct cbWLANTARGET_dataFrame cbWLANTARGET_dataFrame;
|
||||
typedef struct cbWLANTARGET_Handle cbWLANTARGET_Handle;
|
||||
|
||||
|
||||
/**
|
||||
* Copy data from frame data memory to buffer.
|
||||
*
|
||||
* @param buffer The destination buffer.
|
||||
* @param frame Frame memory pointer (@ref cbWLANTARGET_allocDataFrame).
|
||||
* @param size Number of bytes to copy.
|
||||
* @param offsetInFrame Offset into frame memory.
|
||||
* @return @ref TRUE if successful, otherwise @ref FALSE.
|
||||
*/
|
||||
typedef cb_boolean(*cbWLANTARGET_copyFromDataFrame)(cb_uint8* buffer, cbWLANTARGET_dataFrame* frame, cb_uint32 size, cb_uint32 offsetInFrame);
|
||||
|
||||
/**
|
||||
* Copy data from buffer to frame data memory.
|
||||
*
|
||||
* @param frame Frame memory pointer (@ref cbWLANTARGET_allocDataFrame).
|
||||
* @param buffer The destination buffer.
|
||||
* @param size Number of bytes to copy.
|
||||
* @param offsetInFrame Offset into frame memory.
|
||||
* @return @ref TRUE if successful, otherwise @ref FALSE.
|
||||
*/
|
||||
typedef cb_boolean(*cbWLANTARGET_copyToDataFrame)(cbWLANTARGET_dataFrame* frame, cb_uint8* buffer, cb_uint32 size, cb_uint32 offsetInFrame);
|
||||
|
||||
/**
|
||||
* Allocate memory in frame data memory.
|
||||
*
|
||||
* @param size Number of bytes to allocate.
|
||||
* @return Pointer to the frame memory.
|
||||
*
|
||||
* @ref cbWLANTARGET_freeDataFrame
|
||||
*/
|
||||
typedef cbWLANTARGET_dataFrame*(*cbWLANTARGET_allocDataFrame)(cb_uint32 size);
|
||||
|
||||
/**
|
||||
* Destroy memory in frame data memory.
|
||||
*
|
||||
* @param frame Pointer to the frame memory that should be destroyed.
|
||||
* @ref cbWLANTARGET_allocDataFrame
|
||||
*/
|
||||
typedef void(*cbWLANTARGET_freeDataFrame)(cbWLANTARGET_dataFrame* frame);
|
||||
|
||||
typedef cb_uint32(*cbWLANTARGET_getDataFrameSize)(cbWLANTARGET_dataFrame* frame);
|
||||
|
||||
typedef cb_uint8(*cbWLANTARGET_getDataFrameTID)(cbWLANTARGET_dataFrame* frame);
|
||||
|
||||
typedef struct
|
||||
{
|
||||
cbWLANTARGET_copyFromDataFrame copyFromDataFrameIndication;
|
||||
cbWLANTARGET_copyToDataFrame copyToDataFrameIndication;
|
||||
cbWLANTARGET_allocDataFrame allocDataFrameIndication;
|
||||
cbWLANTARGET_freeDataFrame freeDataFrameIndication;
|
||||
cbWLANTARGET_getDataFrameSize getDataFrameSizeIndication;
|
||||
cbWLANTARGET_getDataFrameTID getDataFrameTIDIndication;
|
||||
}cbWLANTARGET_Callback;
|
||||
|
||||
/*===========================================================================
|
||||
* FUNCTIONS
|
||||
*=========================================================================*/
|
||||
|
||||
/**
|
||||
* Register WLAN target callbacks. This should be done for packetization between
|
||||
* the WLAN driver and an IP stack.
|
||||
*
|
||||
* @param callbacks Callbacks
|
||||
*/
|
||||
void cbWLANTARGET_registerCallbacks(cbWLANTARGET_Callback* callbacks);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -0,0 +1,552 @@
|
|||
/*---------------------------------------------------------------------------
|
||||
* Copyright (c) 2016, u-blox Malmö, All Rights Reserved
|
||||
* SPDX-License-Identifier: LicenseRef-PBL
|
||||
*
|
||||
* This file and the related binary are licensed under the
|
||||
* Permissive Binary License, Version 1.0 (the "License");
|
||||
* you may not use these files except in compliance with the License.
|
||||
*
|
||||
* You may obtain a copy of the License here:
|
||||
* LICENSE-permissive-binary-license-1.0.txt and at
|
||||
* https://www.mbed.com/licenses/PBL-1.0
|
||||
*
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* Component : WLAN driver
|
||||
* File : cb_wlan_types.h
|
||||
*
|
||||
* Description : Common wireless LAN defines and types.
|
||||
*-------------------------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
* @file cb_wlan_types.h The main WLAN 802.11 interface
|
||||
*
|
||||
* @ingroup WLANDriver
|
||||
*/
|
||||
|
||||
#ifndef _CB_WLAN_TYPES_H_
|
||||
#define _CB_WLAN_TYPES_H_
|
||||
|
||||
#include "cb_types.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*===========================================================================
|
||||
* DEFINES
|
||||
*=========================================================================*/
|
||||
|
||||
/**
|
||||
* Max length for an SSID
|
||||
*
|
||||
* @ingroup wlantypes
|
||||
*/
|
||||
#define cbWLAN_SSID_MAX_LENGTH (32)
|
||||
|
||||
/**
|
||||
* EAPOL ethernet type
|
||||
*
|
||||
* @ingroup wlantypes
|
||||
*/
|
||||
#define cbWLAN_ETHTYPE_EAPOL (0x888E)
|
||||
|
||||
/**
|
||||
* Maximum size of a predefined WEP key
|
||||
*
|
||||
* @ingroup wlantypes
|
||||
*/
|
||||
#define cbWLAN_KEY_SIZE_WEP_MAX (cbWLAN_KEY_SIZE_WEP128)
|
||||
|
||||
#define cbWLAN_OUI_SIZE 3
|
||||
|
||||
#define cbRATE_MASK_B (cbRATE_MASK_01 | cbRATE_MASK_02 | cbRATE_MASK_5_5 | cbRATE_MASK_11)
|
||||
#define cbRATE_MASK_G (cbRATE_MASK_06 | cbRATE_MASK_09 | cbRATE_MASK_12 | cbRATE_MASK_18 | cbRATE_MASK_24 | cbRATE_MASK_36 | cbRATE_MASK_48 | cbRATE_MASK_54)
|
||||
#define cbRATE_MASK_N (cbRATE_MASK_MCS0 | cbRATE_MASK_MCS1 | cbRATE_MASK_MCS2 | cbRATE_MASK_MCS3 | cbRATE_MASK_MCS4 | cbRATE_MASK_MCS5 | cbRATE_MASK_MCS6 | cbRATE_MASK_MCS7)
|
||||
#define cbRATE_MASK_ALL (cbRATE_MASK_B | cbRATE_MASK_G | cbRATE_MASK_N)
|
||||
|
||||
#define cbWLAN_MAX_CHANNEL_LIST_LENGTH 38
|
||||
|
||||
#define cbWLAN_TX_POWER_AUTO 0xFF
|
||||
|
||||
/*===========================================================================
|
||||
* TYPES
|
||||
*=========================================================================*/
|
||||
|
||||
/**
|
||||
* The encryption mode.
|
||||
*
|
||||
* @ingroup wlantypes
|
||||
*/
|
||||
typedef enum cbWLAN_EncryptionMode_e {
|
||||
cbWLAN_ENC_NONE,
|
||||
cbWLAN_ENC_WEP64,
|
||||
cbWLAN_ENC_WEP128,
|
||||
cbWLAN_ENC_TKIP,
|
||||
cbWLAN_ENC_AES,
|
||||
} cbWLAN_EncryptionMode;
|
||||
|
||||
|
||||
/**
|
||||
* Enterprise authentication mode.
|
||||
*
|
||||
* @ingroup wlan
|
||||
*/
|
||||
typedef enum cbWLAN_EnterpriseMode {
|
||||
cbWLAN_ENTERPRISE_MODE_LEAP,
|
||||
cbWLAN_ENTERPRISE_MODE_PEAP,
|
||||
cbWLAN_ENTERPRISE_MODE_EAPTLS,
|
||||
} cbWLAN_EnterpriseMode;
|
||||
|
||||
/**
|
||||
* Key sizes for the supported encryptions.
|
||||
*
|
||||
* @ingroup wlantypes
|
||||
*/
|
||||
typedef enum cbWLAN_EncryptionKeySize_e {
|
||||
cbWLAN_KEY_SIZE_WEP64 = 5,
|
||||
cbWLAN_KEY_SIZE_WEP128 = 13,
|
||||
cbWLAN_KEY_SIZE_WEP2 = 16,
|
||||
cbWLAN_KEY_SIZE_TKIP = 16,
|
||||
cbWLAN_KEY_SIZE_AES = 16,
|
||||
cbWLAN_KEY_SIZE_TKIP_MIC = 8
|
||||
} cbWLAN_EncryptionKeySize;
|
||||
|
||||
enum cbWLAN_Channel_e {
|
||||
cbWLAN_CHANNEL_ALL = 0,
|
||||
cbWLAN_CHANNEL_01 = 1,
|
||||
cbWLAN_CHANNEL_02,
|
||||
cbWLAN_CHANNEL_03,
|
||||
cbWLAN_CHANNEL_04,
|
||||
cbWLAN_CHANNEL_05,
|
||||
cbWLAN_CHANNEL_06,
|
||||
cbWLAN_CHANNEL_07,
|
||||
cbWLAN_CHANNEL_08,
|
||||
cbWLAN_CHANNEL_09,
|
||||
cbWLAN_CHANNEL_10,
|
||||
cbWLAN_CHANNEL_11,
|
||||
cbWLAN_CHANNEL_12,
|
||||
cbWLAN_CHANNEL_13,
|
||||
cbWLAN_CHANNEL_14,
|
||||
|
||||
cbWLAN_CHANNEL_36 = 36,
|
||||
cbWLAN_CHANNEL_40 = 40,
|
||||
cbWLAN_CHANNEL_44 = 44,
|
||||
cbWLAN_CHANNEL_48 = 48,
|
||||
cbWLAN_CHANNEL_52 = 52,
|
||||
cbWLAN_CHANNEL_56 = 56,
|
||||
cbWLAN_CHANNEL_60 = 60,
|
||||
cbWLAN_CHANNEL_64 = 64,
|
||||
cbWLAN_CHANNEL_100 = 100,
|
||||
cbWLAN_CHANNEL_104 = 104,
|
||||
cbWLAN_CHANNEL_108 = 108,
|
||||
cbWLAN_CHANNEL_112 = 112,
|
||||
cbWLAN_CHANNEL_116 = 116,
|
||||
cbWLAN_CHANNEL_120 = 120,
|
||||
cbWLAN_CHANNEL_124 = 124,
|
||||
cbWLAN_CHANNEL_128 = 128,
|
||||
cbWLAN_CHANNEL_132 = 132,
|
||||
cbWLAN_CHANNEL_136 = 136,
|
||||
cbWLAN_CHANNEL_140 = 140,
|
||||
cbWLAN_CHANNEL_149 = 149,
|
||||
cbWLAN_CHANNEL_153 = 153,
|
||||
cbWLAN_CHANNEL_157 = 157,
|
||||
cbWLAN_CHANNEL_161 = 161,
|
||||
cbWLAN_CHANNEL_165 = 165
|
||||
};
|
||||
|
||||
/**
|
||||
* WLAN Channels
|
||||
* Valid values are found in @ref cbWLAN_Channel_e
|
||||
* @ingroup wlantypes
|
||||
*/
|
||||
typedef cb_uint8 cbWLAN_Channel;
|
||||
|
||||
/**
|
||||
* WLAN Channel list
|
||||
* @ingroup wlantypes
|
||||
*/
|
||||
typedef struct {
|
||||
cb_uint32 length;
|
||||
cbWLAN_Channel channels[cbWLAN_MAX_CHANNEL_LIST_LENGTH];
|
||||
} cbWLAN_ChannelList;
|
||||
|
||||
/**
|
||||
* Standard 802.11 rates
|
||||
*
|
||||
* @ingroup wlantypes
|
||||
*/
|
||||
enum cbWLAN_Rate_e {
|
||||
cbWLAN_RATE_01 = 1, // 1
|
||||
cbWLAN_RATE_02, // 2
|
||||
cbWLAN_RATE_5_5, // 3
|
||||
cbWLAN_RATE_06, // 4
|
||||
cbWLAN_RATE_09, // 5
|
||||
cbWLAN_RATE_11, // 6
|
||||
cbWLAN_RATE_12, // 7
|
||||
cbWLAN_RATE_18, // 8
|
||||
cbWLAN_RATE_24, // 9
|
||||
cbWLAN_RATE_36, // 10
|
||||
cbWLAN_RATE_48, // 11
|
||||
cbWLAN_RATE_54, // 12
|
||||
cbWLAN_RATE_MCS0, // 13
|
||||
cbWLAN_RATE_MCS1, // 14
|
||||
cbWLAN_RATE_MCS2, // 15
|
||||
cbWLAN_RATE_MCS3, // 16
|
||||
cbWLAN_RATE_MCS4, // 17
|
||||
cbWLAN_RATE_MCS5, // 18
|
||||
cbWLAN_RATE_MCS6, // 19
|
||||
cbWLAN_RATE_MCS7, // 20
|
||||
cbWLAN_RATE_MCS8, // 21
|
||||
cbWLAN_RATE_MCS9, // 22
|
||||
cbWLAN_RATE_MCS10, // 23
|
||||
cbWLAN_RATE_MCS11, // 24
|
||||
cbWLAN_RATE_MCS12, // 25
|
||||
cbWLAN_RATE_MCS13, // 26
|
||||
cbWLAN_RATE_MCS14, // 27
|
||||
cbWLAN_RATE_MCS15, // 28
|
||||
};
|
||||
|
||||
/**
|
||||
* Type for containing values found in @ref cbWLAN_Rate_e
|
||||
* @ingroup wlantypes
|
||||
*/
|
||||
typedef cb_uint8 cbWLAN_Rate;
|
||||
|
||||
|
||||
/**
|
||||
* Mask bits for standard 802.11 rates
|
||||
*
|
||||
* @ingroup wlantypes
|
||||
*/
|
||||
enum cbWLAN_RateMask_e {
|
||||
cbRATE_MASK_01 = 0x00000001,
|
||||
cbRATE_MASK_02 = 0x00000002,
|
||||
cbRATE_MASK_5_5 = 0x00000004,
|
||||
cbRATE_MASK_11 = 0x00000008,
|
||||
cbRATE_MASK_06 = 0x00000010,
|
||||
cbRATE_MASK_09 = 0x00000020,
|
||||
cbRATE_MASK_12 = 0x00000040,
|
||||
cbRATE_MASK_18 = 0x00000080,
|
||||
cbRATE_MASK_24 = 0x00000100,
|
||||
cbRATE_MASK_36 = 0x00000200,
|
||||
cbRATE_MASK_48 = 0x00000400,
|
||||
cbRATE_MASK_54 = 0x00000800,
|
||||
// NOTE: Don't move MCS rates bit offset, see note on define below
|
||||
cbRATE_MASK_MCS0 = 0x00001000,
|
||||
cbRATE_MASK_MCS1 = 0x00002000,
|
||||
cbRATE_MASK_MCS2 = 0x00004000,
|
||||
cbRATE_MASK_MCS3 = 0x00008000,
|
||||
cbRATE_MASK_MCS4 = 0x00010000,
|
||||
cbRATE_MASK_MCS5 = 0x00020000,
|
||||
cbRATE_MASK_MCS6 = 0x00040000,
|
||||
cbRATE_MASK_MCS7 = 0x00080000,
|
||||
cbRATE_MASK_MCS8 = 0x00100000,
|
||||
cbRATE_MASK_MCS9 = 0x00200000,
|
||||
cbRATE_MASK_MCS10 = 0x00400000,
|
||||
cbRATE_MASK_MCS11 = 0x00800000,
|
||||
cbRATE_MASK_MCS12 = 0x01000000,
|
||||
cbRATE_MASK_MCS13 = 0x02000000,
|
||||
cbRATE_MASK_MCS14 = 0x04000000,
|
||||
cbRATE_MASK_MCS15 = 0x08000000,
|
||||
};
|
||||
|
||||
/**
|
||||
* Access categories
|
||||
*
|
||||
* @ingroup wlantypes
|
||||
*/
|
||||
typedef enum cbWLAN_AccessCategory_e {
|
||||
cbWLAN_AC_BK = 1, /**< Background */
|
||||
cbWLAN_AC_SP = 2, /**< Background (Spare) */
|
||||
|
||||
cbWLAN_AC_BE = 0, /**< Best effort */
|
||||
cbWLAN_AC_EE = 3, /**< Best effort (Excellent Effort) */
|
||||
|
||||
cbWLAN_AC_CL = 4, /**< Video (Controlled Load) */
|
||||
cbWLAN_AC_VI = 5, /**< Video */
|
||||
|
||||
cbWLAN_AC_VO = 6, /**< Voice */
|
||||
cbWLAN_AC_NC = 7, /**< Voice (Network Control)*/
|
||||
} cbWLAN_AccessCategory;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* connectBlue Hardware Identification
|
||||
*
|
||||
* @ingroup types
|
||||
*/
|
||||
typedef enum cbWM_ModuleType_e {
|
||||
cbWM_MODULE_UNKNOWN,
|
||||
cbWM_MODULE_OWL22X,
|
||||
cbWM_MODULE_OWL253,
|
||||
cbWM_MODULE_OWS451,
|
||||
cbWM_MODULE_OWL351,
|
||||
cbWM_MODULE_ODIN_W16X = cbWM_MODULE_OWL351,
|
||||
cbWM_MODULE_ODIN_W26X,
|
||||
} cbWM_ModuleType;
|
||||
|
||||
/**
|
||||
* Mac address type
|
||||
*
|
||||
* @ingroup wlantypes
|
||||
*/
|
||||
typedef cb_uint8 cbWLAN_MACAddress[6];
|
||||
|
||||
/**
|
||||
* Type for containing values found in @ref cbWLAN_RateMask_e
|
||||
* @ingroup wlantypes
|
||||
*/
|
||||
typedef cb_uint32 cbWLAN_RateMask;
|
||||
|
||||
/**
|
||||
* Transmission power
|
||||
*
|
||||
* @ingroup wlantypes
|
||||
*/
|
||||
typedef cb_uint8 cbWLAN_TxPower;
|
||||
|
||||
/**
|
||||
* The different frequency bands to choose from.
|
||||
*
|
||||
* @ingroup wlantypes
|
||||
*/
|
||||
typedef enum cbWLAN_Band_e {
|
||||
cbWLAN_BAND_UNDEFINED,
|
||||
cbWLAN_BAND_2_4GHz,
|
||||
cbWLAN_BAND_5GHz,
|
||||
} cbWLAN_Band;
|
||||
|
||||
/**
|
||||
* The operational mode.
|
||||
*
|
||||
* @ingroup wlantypes
|
||||
*/
|
||||
typedef enum cbWLAN_OperationalMode_e {
|
||||
cbWLAN_OPMODE_MANAGED,
|
||||
cbWLAN_OPMODE_ADHOC,
|
||||
} cbWLAN_OperationalMode;
|
||||
|
||||
/**
|
||||
* Encryption key type
|
||||
*
|
||||
* @ingroup wlantypes
|
||||
*/
|
||||
typedef enum cbWLAN_KeyType_e {
|
||||
cbWLAN_KEY_UNICAST,
|
||||
cbWLAN_KEY_BROADCAST,
|
||||
} cbWLAN_KeyType;
|
||||
|
||||
typedef enum {
|
||||
cbWLAN_CONNECT_MODE_OPEN,
|
||||
cbWLAN_CONNECT_MODE_WEP_OPEN,
|
||||
cbWLAN_CONNECT_MODE_WPA_PSK,
|
||||
cbWLAN_CONNECT_MODE_ENTERPRISE,
|
||||
} cbWLAN_ConnectMode;
|
||||
|
||||
typedef enum {
|
||||
cbWLAN_AP_MODE_OPEN,
|
||||
cbWLAN_AP_MODE_WEP_OPEN,
|
||||
cbWLAN_AP_MODE_WPA_PSK,
|
||||
cbWLAN_AP_MODE_ENTERPRISE,
|
||||
} cbWLAN_ApMode;
|
||||
|
||||
/**
|
||||
* Ethernet header
|
||||
*
|
||||
* @ingroup wlantypes
|
||||
*/
|
||||
cb_PACKED_STRUCT_BEGIN(cbWLAN_EthernetHeader) {
|
||||
cbWLAN_MACAddress dest;
|
||||
cbWLAN_MACAddress src;
|
||||
cb_uint16 type;
|
||||
} cb_PACKED_STRUCT_END(cbWLAN_EthernetHeader);
|
||||
|
||||
|
||||
cb_PACKED_STRUCT_BEGIN(cbWLAN_EthernetFrame) {
|
||||
cbWLAN_EthernetHeader header;
|
||||
cb_uint8 payload[cb_EMPTY_ARRAY];
|
||||
} cb_PACKED_STRUCT_END(cbWLAN_EthernetFrame);
|
||||
|
||||
/**
|
||||
* SNAP header
|
||||
*
|
||||
* @ingroup wlantypes
|
||||
*/
|
||||
cb_PACKED_STRUCT_BEGIN(cbWLAN_SNAPHeader) {
|
||||
cb_uint8 dsap;
|
||||
cb_uint8 ssap;
|
||||
cb_uint8 ctrl;
|
||||
cb_uint8 encapsulation[3];
|
||||
cb_uint16 ethType;
|
||||
} cb_PACKED_STRUCT_END(cbWLAN_SNAPHeader);
|
||||
|
||||
cb_PACKED_STRUCT_BEGIN(cbWLAN_SNAPFrame) {
|
||||
cbWLAN_SNAPHeader header;
|
||||
cb_uint8 payload[cb_EMPTY_ARRAY];
|
||||
} cb_PACKED_STRUCT_END(cbWLAN_SNAPFrame);
|
||||
|
||||
|
||||
/**
|
||||
* Defines an ssid.
|
||||
*
|
||||
* @ingroup wlantypes
|
||||
*/
|
||||
typedef struct cbWLAN_Ssid_s {
|
||||
cb_uint8 ssid[cbWLAN_SSID_MAX_LENGTH];
|
||||
cb_uint32 ssidLength;
|
||||
} cbWLAN_Ssid;
|
||||
|
||||
/**
|
||||
* Defines one wep key.
|
||||
*
|
||||
* @ingroup wlantypes
|
||||
*/
|
||||
typedef struct cbWLAN_WepKey_s {
|
||||
cb_uint8 key[cbWLAN_KEY_SIZE_WEP_MAX];
|
||||
cb_uint32 length;
|
||||
} cbWLAN_WEPKey;
|
||||
|
||||
/**
|
||||
* Describes host revisions.
|
||||
* @see cbWM_Version
|
||||
*
|
||||
* @ingroup types
|
||||
*/
|
||||
typedef struct {
|
||||
struct {
|
||||
cb_uint32 major;
|
||||
cb_uint32 minor;
|
||||
cb_uint32 patch1;
|
||||
} software;
|
||||
struct {
|
||||
const char* id;
|
||||
} manufacturer;
|
||||
} cbWM_DriverRevision;
|
||||
|
||||
/**
|
||||
* Describes firmware revisions.
|
||||
* @see cbWM_Version
|
||||
*
|
||||
* @ingroup types
|
||||
*/
|
||||
typedef struct {
|
||||
struct {
|
||||
cb_uint32 major;
|
||||
cb_uint32 minor;
|
||||
cb_uint32 patch1;
|
||||
cb_uint32 patch2;
|
||||
} firmware;
|
||||
struct {
|
||||
const char* id;
|
||||
} manufacturer;
|
||||
} cbWM_FWRevision;
|
||||
|
||||
/**
|
||||
* Describes firmware revisions. Is divided into three parts; one for the
|
||||
* host driver side, one for target firmware, and one information string
|
||||
* descibing the HW manufacturer.
|
||||
*
|
||||
* @ingroup types
|
||||
*/
|
||||
typedef struct version_st{
|
||||
cbWM_DriverRevision host;
|
||||
cbWM_FWRevision target;
|
||||
} cbWM_Version;
|
||||
|
||||
/**
|
||||
* Describes power levels for dynamic power level control.
|
||||
*
|
||||
* @ingroup types
|
||||
*/
|
||||
typedef struct cbWM_TxPowerSettings_s {
|
||||
cbWLAN_TxPower lowTxPowerLevel;
|
||||
cbWLAN_TxPower medTxPowerLevel;
|
||||
cbWLAN_TxPower maxTxPowerLevel;
|
||||
} cbWM_TxPowerSettings;
|
||||
|
||||
/**
|
||||
* Describes an access point.
|
||||
*
|
||||
* @ingroup types
|
||||
*/
|
||||
typedef struct cbWLAN_ApInformation {
|
||||
cbWLAN_Ssid ssid; /**< SSID */
|
||||
cbWLAN_MACAddress bssid; /**< BSSID */
|
||||
cbWLAN_Channel channel; /**< Channel */
|
||||
} cbWLAN_ApInformation;
|
||||
|
||||
/**
|
||||
* Describes a station connected to an access point.
|
||||
*
|
||||
* @ingroup types
|
||||
*/
|
||||
typedef struct cbWLAN_ApStaInformation {
|
||||
cbWLAN_MACAddress MAC;
|
||||
} cbWLAN_ApStaInformation;
|
||||
|
||||
/*---------------------------------------------------------------------------
|
||||
* VARIABLE DECLARATIONS
|
||||
*-------------------------------------------------------------------------*/
|
||||
extern const cbWLAN_MACAddress nullMac;
|
||||
extern const cbWLAN_MACAddress broadcastMac;
|
||||
|
||||
extern const cb_uint8 OUI_Microsoft[cbWLAN_OUI_SIZE];
|
||||
extern const cb_uint8 OUI_Epigram[cbWLAN_OUI_SIZE];
|
||||
extern const cb_uint8 OUI_ConnectBlue[cbWLAN_OUI_SIZE];
|
||||
extern const cb_uint8 OUI_IEEE8021[cbWLAN_OUI_SIZE];
|
||||
|
||||
extern const cb_uint8 PATTERN_HTInformationDraft[1];
|
||||
extern const cb_uint8 PATTERN_TKIP[2];
|
||||
extern const cb_uint8 PATTERN_WME_IE[3];
|
||||
extern const cb_uint8 PATTERN_WME_PE[3];
|
||||
|
||||
/*---------------------------------------------------------------------------
|
||||
* FUNCTIONS
|
||||
*-------------------------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
* Misc
|
||||
*/
|
||||
|
||||
/**
|
||||
* Returns the correct frequency @ref cbWLAN_Band band based on the input channel.
|
||||
*
|
||||
* For @ref cbWLAN_CHANNEL_ALL This function will return @ref cbWLAN_BAND_2_4GHz.
|
||||
*
|
||||
* @param channel The channel to be queried for band.
|
||||
* @return The @ref cbWLAN_Band band for the requested channel.
|
||||
*/
|
||||
cbWLAN_Band cbWLAN_getBandFromChannel(cbWLAN_Channel channel);
|
||||
|
||||
/**
|
||||
* Returns the valid rates @ref cbWLAN_RateMask based for the channel.
|
||||
*
|
||||
* @param channel The channel to be queried for rates.
|
||||
* @return The valid rates @ref cbWLAN_RateMask for the requested channel.
|
||||
*/
|
||||
cbWLAN_RateMask cbWLAN_getRatesForChannel(cbWLAN_Channel channel);
|
||||
|
||||
/**
|
||||
* Checks is the input rate is a 802.11n rate or not.
|
||||
*
|
||||
* @param rate The rate to check
|
||||
* @return @ref TRUE if the input rate is an n-rate. @ref FALSE otherwise.
|
||||
*/
|
||||
cb_boolean cbWLAN_isNRate(cbWLAN_Rate rate);
|
||||
|
||||
/**
|
||||
* Checks if a channel is valid
|
||||
*
|
||||
* @return @ref TRUE if the channel is valid. @ref FALSE otherwise.
|
||||
*/
|
||||
cb_boolean cbWLAN_isValidChannel(cbWLAN_Channel channel);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
|
@ -0,0 +1,329 @@
|
|||
#if DEVICE_EMAC
|
||||
|
||||
#include <stdio.h>
|
||||
#include "cb_main.h"
|
||||
#include "cb_wlan.h"
|
||||
#include "cb_wlan_types.h"
|
||||
#include "cb_otp.h"
|
||||
#include "cb_wlan_target_data.h"
|
||||
#include "emac_api.h"
|
||||
#include "mbed_assert.h"
|
||||
#include "rtos.h"
|
||||
#include "mbed_events.h"
|
||||
|
||||
/*===========================================================================
|
||||
* DEFINES
|
||||
*=========================================================================*/
|
||||
#define WIFI_EMAC_API_MTU_SIZE (1500U)
|
||||
|
||||
/*===========================================================================
|
||||
* TYPES
|
||||
*=========================================================================*/
|
||||
typedef struct {
|
||||
emac_link_input_fn wifi_input_cb;
|
||||
emac_link_state_change_fn wifi_state_cb;
|
||||
void* link_input_user_data;
|
||||
void* link_state_user_data;
|
||||
bool linkStateRegistered;
|
||||
} wifi_emac_api_s;
|
||||
|
||||
/*===========================================================================
|
||||
* DECLARATIONS
|
||||
*=========================================================================*/
|
||||
static void statusIndication(void *dummy, cbWLAN_StatusIndicationInfo status, void *data);
|
||||
static void packetIndication(void *dummy, cbWLAN_PacketIndicationInfo *packetInfo);
|
||||
static cb_boolean handleWlanTargetCopyFromDataFrame(uint8_t* buffer, cbWLANTARGET_dataFrame* frame, uint32_t size, uint32_t offsetInFrame);
|
||||
static cb_boolean handleWlanTargetCopyToDataFrame(cbWLANTARGET_dataFrame* frame, uint8_t* buffer, uint32_t size, uint32_t offsetInFrame);
|
||||
static cbWLANTARGET_dataFrame* handleWlanTargetAllocDataFrame(uint32_t size);
|
||||
static void handleWlanTargetFreeDataFrame(cbWLANTARGET_dataFrame* frame);
|
||||
static cb_uint32 handleWlanTargetGetDataFrameSize(cbWLANTARGET_dataFrame* frame);
|
||||
static cb_uint8 handleWlanTargetGetDataFrameTID(cbWLANTARGET_dataFrame* frame);
|
||||
|
||||
static uint32_t wifi_get_mtu_size(emac_interface_t *emac);
|
||||
static void wifi_get_ifname(emac_interface_t *emac, char *name, uint8_t size);
|
||||
static uint8_t wifi_get_hwaddr_size(emac_interface_t *emac);
|
||||
static void wifi_get_hwaddr(emac_interface_t *emac, uint8_t *addr);
|
||||
static void wifi_set_hwaddr(emac_interface_t *emac, uint8_t *addr);
|
||||
static bool wifi_link_out(emac_interface_t *emac, emac_stack_mem_t *buf);
|
||||
static bool wifi_power_up(emac_interface_t *emac);
|
||||
static void wifi_power_down(emac_interface_t *emac);
|
||||
static void wifi_set_link_input_cb(emac_interface_t *emac, emac_link_input_fn input_cb, void *data);
|
||||
static void wifi_set_link_state_cb(emac_interface_t *emac, emac_link_state_change_fn state_cb, void *data);
|
||||
|
||||
/*===========================================================================
|
||||
* DEFINITIONS
|
||||
*=========================================================================*/
|
||||
static wifi_emac_api_s _admin;
|
||||
static const char _ifname[] = "WL0";
|
||||
|
||||
const emac_interface_ops_t wifi_emac_interface = {
|
||||
.get_mtu_size = wifi_get_mtu_size,
|
||||
.get_ifname = wifi_get_ifname,
|
||||
.get_hwaddr_size = wifi_get_hwaddr_size,
|
||||
.get_hwaddr = wifi_get_hwaddr,
|
||||
.set_hwaddr = wifi_set_hwaddr,
|
||||
.link_out = wifi_link_out,
|
||||
.power_up = wifi_power_up,
|
||||
.power_down = wifi_power_down,
|
||||
.set_link_input_cb = wifi_set_link_input_cb,
|
||||
.set_link_state_cb = wifi_set_link_state_cb
|
||||
};
|
||||
|
||||
static emac_interface_t _intf = { wifi_emac_interface, NULL };
|
||||
|
||||
static const cbWLANTARGET_Callback _wlanTargetCallback =
|
||||
{
|
||||
handleWlanTargetCopyFromDataFrame,
|
||||
handleWlanTargetCopyToDataFrame,
|
||||
handleWlanTargetAllocDataFrame,
|
||||
handleWlanTargetFreeDataFrame,
|
||||
handleWlanTargetGetDataFrameSize,
|
||||
handleWlanTargetGetDataFrameTID
|
||||
};
|
||||
|
||||
/*===========================================================================
|
||||
* FUNCTIONS
|
||||
*=========================================================================*/
|
||||
static void statusIndication(void *dummy, cbWLAN_StatusIndicationInfo status, void *data)
|
||||
{
|
||||
bool linkUp = false;
|
||||
bool sendCb = true;
|
||||
(void)dummy;
|
||||
(void)data;
|
||||
|
||||
switch (status) {
|
||||
case cbWLAN_STATUS_CONNECTED:
|
||||
case cbWLAN_STATUS_AP_STA_ADDED:
|
||||
linkUp = true;
|
||||
break;
|
||||
case cbWLAN_STATUS_STOPPED:
|
||||
case cbWLAN_STATUS_ERROR:
|
||||
case cbWLAN_STATUS_DISCONNECTED:
|
||||
case cbWLAN_STATUS_CONNECTION_FAILURE:
|
||||
break;
|
||||
case cbWLAN_STATUS_CONNECTING:
|
||||
default:
|
||||
sendCb = false;
|
||||
break;
|
||||
}
|
||||
if (sendCb) {
|
||||
_admin.wifi_state_cb(_admin.link_state_user_data, linkUp);
|
||||
}
|
||||
}
|
||||
|
||||
static void packetIndication(void *dummy, cbWLAN_PacketIndicationInfo *packetInfo)
|
||||
{
|
||||
(void)dummy;
|
||||
_admin.wifi_input_cb(_admin.link_input_user_data, (void*)packetInfo->rxData);
|
||||
}
|
||||
|
||||
static cb_boolean handleWlanTargetCopyFromDataFrame(uint8_t* buffer, cbWLANTARGET_dataFrame* frame, uint32_t size, uint32_t offsetInFrame)
|
||||
{
|
||||
void* dummy = NULL;
|
||||
emac_stack_mem_t** phead = (emac_stack_mem_chain_t **)&frame;
|
||||
emac_stack_mem_t* pbuf;
|
||||
uint32_t copySize, bytesCopied = 0, pbufOffset = 0;
|
||||
|
||||
MBED_ASSERT(frame != NULL);
|
||||
MBED_ASSERT(buffer != NULL);
|
||||
|
||||
pbuf = emac_stack_mem_chain_dequeue(dummy, phead);
|
||||
while (pbuf != NULL) {
|
||||
if ((pbufOffset + emac_stack_mem_len(dummy, pbuf)) >= offsetInFrame) {
|
||||
copySize = cb_MIN(size, emac_stack_mem_len(dummy, pbuf) - (offsetInFrame - pbufOffset));
|
||||
memcpy(buffer, (int8_t *)emac_stack_mem_ptr(dummy, pbuf) + (offsetInFrame - pbufOffset), copySize);
|
||||
buffer += copySize;
|
||||
bytesCopied += copySize;
|
||||
pbuf = emac_stack_mem_chain_dequeue(dummy, phead);
|
||||
break;
|
||||
}
|
||||
pbufOffset += emac_stack_mem_len(dummy, pbuf);
|
||||
pbuf = emac_stack_mem_chain_dequeue(dummy, phead);
|
||||
}
|
||||
|
||||
while (pbuf != NULL && bytesCopied < size) {
|
||||
copySize = cb_MIN(emac_stack_mem_len(dummy, pbuf), size - bytesCopied);
|
||||
memcpy(buffer, emac_stack_mem_ptr(dummy, pbuf), copySize);
|
||||
buffer += copySize;
|
||||
bytesCopied += copySize;
|
||||
pbuf = emac_stack_mem_chain_dequeue(dummy, phead);
|
||||
}
|
||||
|
||||
MBED_ASSERT(bytesCopied <= size);
|
||||
|
||||
return (bytesCopied == size);
|
||||
}
|
||||
|
||||
static cb_boolean handleWlanTargetCopyToDataFrame(cbWLANTARGET_dataFrame* frame, uint8_t* buffer, uint32_t size, uint32_t offsetInFrame)
|
||||
{
|
||||
void* dummy = NULL;
|
||||
emac_stack_mem_t** phead = (emac_stack_mem_chain_t **)&frame;
|
||||
emac_stack_mem_t* pbuf;
|
||||
uint32_t copySize, bytesCopied = 0, pbufOffset = 0;
|
||||
|
||||
MBED_ASSERT(frame != NULL);
|
||||
MBED_ASSERT(buffer != NULL);
|
||||
|
||||
pbuf = emac_stack_mem_chain_dequeue(dummy, phead);
|
||||
while (pbuf != NULL) {
|
||||
if ((pbufOffset + emac_stack_mem_len(dummy, pbuf)) >= offsetInFrame) {
|
||||
copySize = cb_MIN(size, emac_stack_mem_len(dummy, pbuf) - (offsetInFrame - pbufOffset));
|
||||
memcpy((uint8_t *)emac_stack_mem_ptr(dummy, pbuf) + (offsetInFrame - pbufOffset), buffer, copySize);
|
||||
buffer += copySize;
|
||||
bytesCopied += copySize;
|
||||
pbuf = emac_stack_mem_chain_dequeue(dummy, phead);
|
||||
break;
|
||||
}
|
||||
pbufOffset += emac_stack_mem_len(dummy, pbuf);
|
||||
pbuf = emac_stack_mem_chain_dequeue(dummy, phead);
|
||||
}
|
||||
|
||||
while (pbuf != NULL && bytesCopied < size) {
|
||||
copySize = cb_MIN(emac_stack_mem_len(dummy, pbuf), size - bytesCopied);
|
||||
memcpy(emac_stack_mem_ptr(dummy, pbuf), buffer, copySize);
|
||||
buffer += copySize;
|
||||
bytesCopied += copySize;
|
||||
pbuf = emac_stack_mem_chain_dequeue(dummy, phead);
|
||||
}
|
||||
|
||||
MBED_ASSERT(bytesCopied <= size);
|
||||
|
||||
return (bytesCopied == size);
|
||||
}
|
||||
|
||||
static cbWLANTARGET_dataFrame* handleWlanTargetAllocDataFrame(uint32_t size)
|
||||
{
|
||||
void* dummy = NULL;
|
||||
|
||||
return (cbWLANTARGET_dataFrame*)emac_stack_mem_alloc(dummy, size, 0);
|
||||
}
|
||||
|
||||
static void handleWlanTargetFreeDataFrame(cbWLANTARGET_dataFrame* frame)
|
||||
{
|
||||
void* dummy = NULL;
|
||||
|
||||
emac_stack_mem_free(dummy, (emac_stack_mem_t*)frame);
|
||||
}
|
||||
|
||||
static uint32_t handleWlanTargetGetDataFrameSize(cbWLANTARGET_dataFrame* frame)
|
||||
{
|
||||
void* dummy = NULL;
|
||||
return emac_stack_mem_chain_len(dummy, (emac_stack_mem_t*)frame);
|
||||
}
|
||||
|
||||
static uint8_t handleWlanTargetGetDataFrameTID(cbWLANTARGET_dataFrame* frame)
|
||||
{
|
||||
(void)frame;
|
||||
return (uint8_t)cbWLAN_AC_BE;
|
||||
}
|
||||
|
||||
/*===========================================================================
|
||||
* API FUNCTIONS
|
||||
*=========================================================================*/
|
||||
static uint32_t wifi_get_mtu_size(emac_interface_t *emac)
|
||||
{
|
||||
(void)emac;
|
||||
|
||||
return WIFI_EMAC_API_MTU_SIZE;
|
||||
}
|
||||
|
||||
static void wifi_get_ifname(emac_interface_t *emac, char *name, uint8_t size)
|
||||
{
|
||||
(void)emac;
|
||||
MBED_ASSERT(name != NULL);
|
||||
memcpy((void*)name, (void*)&_ifname, cb_MIN(size, sizeof(_ifname)));
|
||||
}
|
||||
|
||||
static uint8_t wifi_get_hwaddr_size(emac_interface_t *emac)
|
||||
{
|
||||
(void)emac;
|
||||
|
||||
return sizeof(cbWLAN_MACAddress);
|
||||
}
|
||||
|
||||
static void wifi_get_hwaddr(emac_interface_t *emac, uint8_t *addr)
|
||||
{
|
||||
(void)emac;
|
||||
|
||||
cbOTP_read(cbOTP_MAC_WLAN, sizeof(cbWLAN_MACAddress), addr);
|
||||
}
|
||||
|
||||
static void wifi_set_hwaddr(emac_interface_t *emac, uint8_t *addr)
|
||||
{
|
||||
(void)emac;
|
||||
(void)addr;
|
||||
|
||||
// Do nothing, not possible to change the address
|
||||
}
|
||||
|
||||
static void send_packet(emac_interface_t *emac, void *buf)
|
||||
{
|
||||
cbWLAN_sendPacket(buf);
|
||||
emac_stack_mem_free(emac,buf);
|
||||
}
|
||||
|
||||
static bool wifi_link_out(emac_interface_t *emac, emac_stack_mem_t *buf)
|
||||
{
|
||||
(void)emac;
|
||||
// Break call chain to avoid the driver affecting stack usage for the IP stack thread too much
|
||||
emac_stack_mem_ref(emac,buf);
|
||||
cbMAIN_getEventQueue()->call(send_packet,emac,buf);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
static bool wifi_power_up(emac_interface_t *emac)
|
||||
{
|
||||
(void)emac;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static void wifi_power_down(emac_interface_t *emac)
|
||||
{
|
||||
(void)emac;
|
||||
}
|
||||
|
||||
static void wifi_set_link_input_cb(emac_interface_t *emac, emac_link_input_fn input_cb, void *data)
|
||||
{
|
||||
void *dummy = NULL;
|
||||
(void)emac;
|
||||
|
||||
_admin.wifi_input_cb = input_cb;
|
||||
_admin.link_input_user_data = data;
|
||||
|
||||
cbMAIN_driverLock();
|
||||
cbWLAN_registerPacketIndicationCallback(packetIndication, dummy);
|
||||
cbMAIN_driverUnlock();
|
||||
}
|
||||
|
||||
static void wifi_set_link_state_cb(emac_interface_t *emac, emac_link_state_change_fn state_cb, void *data)
|
||||
{
|
||||
cbRTSL_Status result;
|
||||
void *dummy = NULL;
|
||||
(void)emac;
|
||||
|
||||
_admin.wifi_state_cb = state_cb;
|
||||
_admin.link_state_user_data = data;
|
||||
|
||||
if (!_admin.linkStateRegistered) {
|
||||
cbMAIN_driverLock();
|
||||
result = cbWLAN_registerStatusCallback(statusIndication, dummy);
|
||||
cbMAIN_driverUnlock();
|
||||
if (result == cbSTATUS_OK) {
|
||||
_admin.linkStateRegistered = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
emac_interface_t* wifi_emac_get_interface()
|
||||
{
|
||||
return &_intf;
|
||||
}
|
||||
|
||||
void wifi_emac_init_mem(void)
|
||||
{
|
||||
cbWLANTARGET_registerCallbacks((cbWLANTARGET_Callback*)&_wlanTargetCallback);
|
||||
}
|
||||
|
||||
#endif
|
|
@ -0,0 +1,10 @@
|
|||
#include "emac_api.h"
|
||||
|
||||
#ifndef WIFI_EMAC_API_H
|
||||
#define WIFI_EMAC_API_H
|
||||
|
||||
emac_interface_t* wifi_emac_get_interface();
|
||||
|
||||
void wifi_emac_init_mem();
|
||||
|
||||
#endif
|
|
@ -1259,7 +1259,7 @@
|
|||
"default_toolchain": "ARM",
|
||||
"supported_toolchains": ["ARM", "uARM", "GCC_ARM", "IAR"],
|
||||
"extra_labels": ["STM", "STM32F4", "STM32F439", "STM32F439ZI","STM32F439xx"],
|
||||
"macros": ["HSE_VALUE=24000000", "HSE_STARTUP_TIMEOUT=5000", "CB_INTERFACE_SDIO","CB_CHIP_WL18XX","SUPPORT_80211D_ALWAYS","WLAN_ENABLED"],
|
||||
"macros": ["HSE_VALUE=24000000", "HSE_STARTUP_TIMEOUT=5000", "CB_INTERFACE_SDIO","CB_CHIP_WL18XX","SUPPORT_80211D_ALWAYS","WLAN_ENABLED","MBEDTLS_USER_CONFIG_FILE=\"sdk/odin_w2_mbedtls_config.h\""],
|
||||
"inherits": ["Target"],
|
||||
"device_has": ["ANALOGIN", "CAN", "I2C", "I2CSLAVE", "INTERRUPTIN", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "SERIAL", "SLEEP", "SPI", "SPISLAVE", "STDIO_MESSAGES", "TRNG"],
|
||||
"features": ["LWIP"],
|
||||
|
|
Loading…
Reference in New Issue