initial commit

This commit is contained in:
2022-10-23 23:45:43 -07:00
commit e190fa5193
6450 changed files with 8626944 additions and 0 deletions
@@ -0,0 +1,423 @@
//*****************************************************************************
//
//! @file amdtp_common.c
//!
//! @brief This file provides the shared functions for the AMDTP service.
//!
//
//*****************************************************************************
//*****************************************************************************
//
// Copyright (c) 2020, Ambiq Micro
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// 3. Neither the name of the copyright holder nor the names of its
// contributors may be used to endorse or promote products derived from this
// software without specific prior written permission.
//
// Third party software included in this distribution is subject to the
// additional license terms as defined in the /docs/licenses directory.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 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.
//
// This is part of revision 2.4.2 of the AmbiqSuite Development Package.
//
//*****************************************************************************
#include <string.h>
#include <stdint.h>
#include <stdlib.h>
#include "amdtp_common.h"
#include "amota_crc32.h"
#include "am_util.h"
extern void amdtps_timeout_timer_expired(void *data, UINT16 datalen);
void
resetPkt(amdtpPacket_t *pkt)
{
pkt->offset = 0;
pkt->header.pktType = AMDTP_PKT_TYPE_UNKNOWN;
pkt->len = 0;
}
eAmdtpStatus_t
AmdtpReceivePkt(amdtpCb_t *amdtpCb, amdtpPacket_t *pkt, uint16_t len, uint8_t *pValue)
{
uint8_t dataIdx = 0;
uint32_t calDataCrc = 0;
uint16_t header = 0;
if (pkt->offset == 0 && len < AMDTP_PREFIX_SIZE_IN_PKT)
{
AMDTP_TRC("Invalid packet!!!\n");
AmdtpSendReply(amdtpCb, AMDTP_STATUS_INVALID_PKT_LENGTH, NULL, 0);
return AMDTP_STATUS_INVALID_PKT_LENGTH;
}
// new packet
if (pkt->offset == 0)
{
BT_UNPACK_LE_2_BYTE(&pkt->len, pValue);
BT_UNPACK_LE_2_BYTE(&header, &pValue[2]);
pkt->header.pktType = (header & PACKET_TYPE_BIT_MASK) >> PACKET_TYPE_BIT_OFFSET;
pkt->header.pktSn = (header & PACKET_SN_BIT_MASK) >> PACKET_SN_BIT_OFFSET;
pkt->header.encrypted = (header & PACKET_ENCRYPTION_BIT_MASK) >> PACKET_ENCRYPTION_BIT_OFFSET;
pkt->header.ackEnabled = (header & PACKET_ACK_BIT_MASK) >> PACKET_ACK_BIT_OFFSET;
dataIdx = AMDTP_PREFIX_SIZE_IN_PKT;
if (pkt->header.pktType == AMDTP_PKT_TYPE_DATA)
{
amdtpCb->rxState = AMDTP_STATE_GETTING_DATA;
}
#ifdef AMDTP_DEBUG_ON
AMDTP_TRC("pkt len = 0x%x\n", pkt->len);
AMDTP_TRC("pkt header = 0x%x\n", header);
#endif
AMDTP_TRC("type = %d, sn = %d\n", pkt->header.pktType, pkt->header.pktSn);
AMDTP_TRC("enc = %d, ackEnabled = %d\n", pkt->header.encrypted, pkt->header.ackEnabled);
}
// make sure we have enough space for new data
if (pkt->offset + len - dataIdx > AMDTP_PACKET_SIZE)
{
AMDTP_TRC("not enough buffer size!!!\n");
if (pkt->header.pktType == AMDTP_PKT_TYPE_DATA)
{
amdtpCb->rxState = AMDTP_STATE_RX_IDLE;
}
// reset pkt
resetPkt(pkt);
AmdtpSendReply(amdtpCb, AMDTP_STATUS_INSUFFICIENT_BUFFER, NULL, 0);
return AMDTP_STATUS_INSUFFICIENT_BUFFER;
}
// copy new data into buffer and also save crc into it if it's the last frame in a packet
// 4 bytes crc is included in pkt length
memcpy(pkt->data + pkt->offset, pValue + dataIdx, len - dataIdx);
pkt->offset += (len - dataIdx);
// whole packet received
if (pkt->offset >= pkt->len)
{
uint32_t peerCrc = 0;
//
// check CRC
//
BT_UNPACK_LE_4_BYTE(&peerCrc, pkt->data + pkt->len - AMDTP_CRC_SIZE_IN_PKT);
calDataCrc = AmotaCrc32(0xFFFFFFFFU, pkt->len - AMDTP_CRC_SIZE_IN_PKT, pkt->data);
#ifdef AMDTP_DEBUG_ON
AMDTP_TRC("calDataCrc = 0x%x\n", calDataCrc);
AMDTP_TRC("peerCrc = 0x%x\n", peerCrc);
AMDTP_TRC("len: %d\n", pkt->len);
#endif
if (peerCrc != calDataCrc)
{
AMDTP_TRC("crc error\n");
if (pkt->header.pktType == AMDTP_PKT_TYPE_DATA)
{
amdtpCb->rxState = AMDTP_STATE_RX_IDLE;
}
// reset pkt
resetPkt(pkt);
AmdtpSendReply(amdtpCb, AMDTP_STATUS_CRC_ERROR, NULL, 0);
return AMDTP_STATUS_CRC_ERROR;
}
return AMDTP_STATUS_RECEIVE_DONE;
}
return AMDTP_STATUS_RECEIVE_CONTINUE;
}
//*****************************************************************************
//
// AMDTP packet handler
//
//*****************************************************************************
void
AmdtpPacketHandler(amdtpCb_t *amdtpCb, eAmdtpPktType_t type, uint16_t len, uint8_t *buf)
{
#ifdef AMDTP_DEBUG_ON
AMDTP_TRC("received packet type = %d, len = %d\n", type, len);
#endif
switch(type)
{
case AMDTP_PKT_TYPE_DATA:
//
// data package recevied
//
// record packet serial number
amdtpCb->lastRxPktSn = amdtpCb->rxPkt.header.pktSn;
AmdtpSendReply(amdtpCb, AMDTP_STATUS_SUCCESS, NULL, 0);
if (amdtpCb->recvCback)
{
amdtpCb->recvCback(buf, len);
}
amdtpCb->rxState = AMDTP_STATE_RX_IDLE;
resetPkt(&amdtpCb->rxPkt);
break;
case AMDTP_PKT_TYPE_ACK:
{
eAmdtpStatus_t status = (eAmdtpStatus_t)buf[0];
// stop tx timeout timer
if (BT_TIMER_HANDLE_INIT_VAL != amdtpCb->timeoutTimer)
{
#ifdef AMDTP_DEBUG_ON
API_RESULT retval = API_SUCCESS;
retval = BT_stop_timer (amdtpCb->timeoutTimer);
AMDTP_TRC (
"[AMDTP]: Stopping Timer with result 0x%04X, timer handle %p\n",
retval, amdtpCb->timeoutTimer);
#else
BT_stop_timer (amdtpCb->timeoutTimer);
#endif
amdtpCb->timeoutTimer = BT_TIMER_HANDLE_INIT_VAL;
}
if (amdtpCb->txState != AMDTP_STATE_TX_IDLE)
{
#ifdef AMDTP_DEBUG_ON
AMDTP_TRC("set txState back to idle, state = %d\n", amdtpCb->txState);
#endif
amdtpCb->txState = AMDTP_STATE_TX_IDLE;
}
if (status == AMDTP_STATUS_CRC_ERROR || status == AMDTP_STATUS_RESEND_REPLY)
{
// resend packet
AmdtpSendPacketHandler(amdtpCb);
}
else
{
// increase packet serial number if send successfully
if (status == AMDTP_STATUS_SUCCESS)
{
amdtpCb->txPktSn++;
if (amdtpCb->txPktSn == 16)
{
amdtpCb->txPktSn = 0;
}
}
// packet transfer successful or other error
// reset packet
resetPkt(&amdtpCb->txPkt);
// notify application layer
if (amdtpCb->transCback)
{
amdtpCb->transCback(status);
}
}
resetPkt(&amdtpCb->ackPkt);
}
break;
case AMDTP_PKT_TYPE_CONTROL:
{
eAmdtpControl_t control = (eAmdtpControl_t)buf[0];
uint8_t resendPktSn = buf[1];
if (control == AMDTP_CONTROL_RESEND_REQ)
{
AMDTP_TRC("resendPktSn = %d, lastRxPktSn = %d\n", resendPktSn, amdtpCb->lastRxPktSn);
amdtpCb->rxState = AMDTP_STATE_RX_IDLE;
resetPkt(&amdtpCb->rxPkt);
if (resendPktSn > amdtpCb->lastRxPktSn)
{
AmdtpSendReply(amdtpCb, AMDTP_STATUS_RESEND_REPLY, NULL, 0);
}
else if (resendPktSn == amdtpCb->lastRxPktSn)
{
AmdtpSendReply(amdtpCb, AMDTP_STATUS_SUCCESS, NULL, 0);
}
else
{
AMDTP_ERR("resendPktSn = %d, lastRxPktSn = %d\n", resendPktSn, amdtpCb->lastRxPktSn);
}
}
else
{
AMDTP_TRC("unexpected contrl = %d\n", control);
}
resetPkt(&amdtpCb->ackPkt);
}
break;
default:
break;
}
}
void
AmdtpBuildPkt(amdtpCb_t *amdtpCb, eAmdtpPktType_t type, BOOLEAN encrypted, BOOLEAN enableACK, uint8_t *buf, uint16_t len)
{
uint16_t header = 0;
uint32_t calDataCrc;
amdtpPacket_t *pkt;
if (type == AMDTP_PKT_TYPE_DATA)
{
pkt = &amdtpCb->txPkt;
header = amdtpCb->txPktSn << PACKET_SN_BIT_OFFSET;
}
else
{
pkt = &amdtpCb->ackPkt;
}
//
// Prepare header frame to be sent first
//
// length
pkt->len = len + AMDTP_PREFIX_SIZE_IN_PKT + AMDTP_CRC_SIZE_IN_PKT;
pkt->data[0] = (len + AMDTP_CRC_SIZE_IN_PKT) & 0xff;
pkt->data[1] = ((len + AMDTP_CRC_SIZE_IN_PKT) >> 8) & 0xff;
// header
header = header | (type << PACKET_TYPE_BIT_OFFSET);
if (encrypted)
{
header = header | (1 << PACKET_ENCRYPTION_BIT_OFFSET);
}
if (enableACK)
{
header = header | (1 << PACKET_ACK_BIT_OFFSET);
}
pkt->data[2] = (header & 0xff);
pkt->data[3] = (header >> 8);
// copy data
memcpy(&(pkt->data[AMDTP_PREFIX_SIZE_IN_PKT]), buf, len);
calDataCrc = AmotaCrc32(0xFFFFFFFFU, len, buf);
// add checksum
pkt->data[AMDTP_PREFIX_SIZE_IN_PKT + len] = (calDataCrc & 0xff);
pkt->data[AMDTP_PREFIX_SIZE_IN_PKT + len + 1] = ((calDataCrc >> 8) & 0xff);
pkt->data[AMDTP_PREFIX_SIZE_IN_PKT + len + 2] = ((calDataCrc >> 16) & 0xff);
pkt->data[AMDTP_PREFIX_SIZE_IN_PKT + len + 3] = ((calDataCrc >> 24) & 0xff);
}
//*****************************************************************************
//
// Send Reply to Sender
//
//*****************************************************************************
void
AmdtpSendReply(amdtpCb_t *amdtpCb, eAmdtpStatus_t status, uint8_t *data, uint16_t len)
{
uint8_t buf[ATT_DEFAULT_PAYLOAD_LEN] = {0};
eAmdtpStatus_t st;
buf[0] = status;
if (len > 0)
{
memcpy(buf + 1, data, len);
}
st = amdtpCb->ack_sender_func(AMDTP_PKT_TYPE_ACK, false, false, buf, len + 1);
if (st != AMDTP_STATUS_SUCCESS)
{
AMDTP_ERR("AmdtpSendReply status = %d\n", status);
}
}
//*****************************************************************************
//
// Send control message to Receiver
//
//*****************************************************************************
void
AmdtpSendControl(amdtpCb_t *amdtpCb, eAmdtpControl_t control, uint8_t *data, uint16_t len)
{
uint8_t buf[ATT_DEFAULT_PAYLOAD_LEN] = {0};
eAmdtpStatus_t st;
buf[0] = control;
if (len > 0)
{
memcpy(buf + 1, data, len);
}
st = amdtpCb->ack_sender_func(AMDTP_PKT_TYPE_CONTROL, false, false, buf, len + 1);
if (st != AMDTP_STATUS_SUCCESS)
{
AMDTP_ERR("AmdtpSendControl status = %d\n", st);
}
}
void
AmdtpSendPacketHandler(amdtpCb_t *amdtpCb)
{
uint16_t transferSize = 0;
uint16_t remainingBytes = 0;
amdtpPacket_t *txPkt = &amdtpCb->txPkt;
API_RESULT retval = API_SUCCESS;
if ( amdtpCb->txState == AMDTP_STATE_TX_IDLE )
{
txPkt->offset = 0;
amdtpCb->txState = AMDTP_STATE_SENDING;
}
if ( txPkt->offset >= txPkt->len )
{
// done sent packet
amdtpCb->txState = AMDTP_STATE_WAITING_ACK;
// start tx timeout timer
if (BT_TIMER_HANDLE_INIT_VAL != amdtpCb->timeoutTimer)
{
retval = BT_stop_timer (amdtpCb->timeoutTimer);
AMDTP_TRC (
"[AMDTP]: Stopping Timer with result 0x%04X, timer handle %p\n",
retval, amdtpCb->timeoutTimer);
amdtpCb->timeoutTimer = BT_TIMER_HANDLE_INIT_VAL;
}
retval = BT_start_timer
(
&amdtpCb->timeoutTimer,
amdtpCb->txTimeout,
amdtps_timeout_timer_expired,
NULL,
0
);
}
else
{
remainingBytes = txPkt->len - txPkt->offset;
transferSize = ((amdtpCb->attMtuSize - 3) > remainingBytes)
? remainingBytes
: (amdtpCb->attMtuSize - 3);
// send packet
amdtpCb->data_sender_func(&txPkt->data[txPkt->offset], transferSize);
txPkt->offset += transferSize;
}
}
@@ -0,0 +1,217 @@
//*****************************************************************************
//
//! @file amdtp_common.h
//!
//! @brief This file provides the shared functions for the AMDTP service.
//
//*****************************************************************************
//*****************************************************************************
//
// Copyright (c) 2020, Ambiq Micro
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// 3. Neither the name of the copyright holder nor the names of its
// contributors may be used to endorse or promote products derived from this
// software without specific prior written permission.
//
// Third party software included in this distribution is subject to the
// additional license terms as defined in the /docs/licenses directory.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 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.
//
// This is part of revision 2.4.2 of the AmbiqSuite Development Package.
//
//*****************************************************************************
#ifndef AMDTP_COMMON_H
#define AMDTP_COMMON_H
#include "BT_api.h"
//*****************************************************************************
//
// Macro definitions
//
//*****************************************************************************
#define BT_MODULE_BIT_MASK_AMDTPS 0x00020000
#define BT_MODULE_ID_AMDTPS (BT_MODULE_PAGE_2 | BT_MODULE_BIT_MASK_AMDTPS)
#define AMDTP_ERR(...) BT_debug_error(BT_MODULE_ID_AMDTPS, __VA_ARGS__)
#define AMDTP_TRC(...) BT_debug_trace(BT_MODULE_ID_AMDTPS, __VA_ARGS__)
#define AMDTP_MAX_PAYLOAD_SIZE 2048 //512
#define AMDTP_PACKET_SIZE (AMDTP_MAX_PAYLOAD_SIZE + AMDTP_PREFIX_SIZE_IN_PKT + AMDTP_CRC_SIZE_IN_PKT) // Bytes
#define AMDTP_LENGTH_SIZE_IN_PKT 2
#define AMDTP_HEADER_SIZE_IN_PKT 2
#define AMDTP_CRC_SIZE_IN_PKT 4
#define AMDTP_PREFIX_SIZE_IN_PKT AMDTP_LENGTH_SIZE_IN_PKT + AMDTP_HEADER_SIZE_IN_PKT
#define PACKET_TYPE_BIT_OFFSET 12
#define PACKET_TYPE_BIT_MASK (0xf << PACKET_TYPE_BIT_OFFSET)
#define PACKET_SN_BIT_OFFSET 8
#define PACKET_SN_BIT_MASK (0xf << PACKET_SN_BIT_OFFSET)
#define PACKET_ENCRYPTION_BIT_OFFSET 7
#define PACKET_ENCRYPTION_BIT_MASK (0x1 << PACKET_ENCRYPTION_BIT_OFFSET)
#define PACKET_ACK_BIT_OFFSET 6
#define PACKET_ACK_BIT_MASK (0x1 << PACKET_ACK_BIT_OFFSET)
#define TX_TIMEOUT_DEFAULT 1 // 1 second
#define ATT_DEFAULT_PAYLOAD_LEN 20
//
// amdtp states
//
typedef enum eAmdtpState
{
AMDTP_STATE_INIT,
AMDTP_STATE_TX_IDLE,
AMDTP_STATE_RX_IDLE,
AMDTP_STATE_SENDING,
AMDTP_STATE_GETTING_DATA,
AMDTP_STATE_WAITING_ACK,
AMDTP_STATE_MAX
}eAmdtpState_t;
//
// amdtp packet type
//
typedef enum eAmdtpPktType
{
AMDTP_PKT_TYPE_UNKNOWN,
AMDTP_PKT_TYPE_DATA,
AMDTP_PKT_TYPE_ACK,
AMDTP_PKT_TYPE_CONTROL,
AMDTP_PKT_TYPE_MAX
}eAmdtpPktType_t;
typedef enum eAmdtpControl
{
AMDTP_CONTROL_RESEND_REQ,
AMDTP_CONTROL_MAX
}eAmdtpControl_t;
//
// amdtp status
//
typedef enum eAmdtpStatus
{
AMDTP_STATUS_SUCCESS,
AMDTP_STATUS_CRC_ERROR,
AMDTP_STATUS_INVALID_METADATA_INFO,
AMDTP_STATUS_INVALID_PKT_LENGTH,
AMDTP_STATUS_INSUFFICIENT_BUFFER,
AMDTP_STATUS_UNKNOWN_ERROR,
AMDTP_STATUS_BUSY,
AMDTP_STATUS_TX_NOT_READY, // no connection or tx busy
AMDTP_STATUS_RESEND_REPLY,
AMDTP_STATUS_RECEIVE_CONTINUE,
AMDTP_STATUS_RECEIVE_DONE,
AMDTP_STATUS_MAX
}eAmdtpStatus_t;
//
// packet prefix structure
//
typedef struct
{
uint8_t pktType : 4;
uint8_t pktSn : 4;
uint8_t encrypted : 1;
uint32_t ackEnabled : 1;
uint32_t reserved : 6; // Reserved for future usage
}
amdtpPktHeader_t;
//
// packet
//
typedef struct
{
uint16_t offset;
uint16_t len; // data plus checksum
amdtpPktHeader_t header;
uint8_t *data;
}
amdtpPacket_t;
/*! Application data reception callback */
typedef void (*amdtpRecvCback_t)(uint8_t *buf, uint16_t len);
/*! Application data transmission result callback */
typedef void (*amdtpTransCback_t)(eAmdtpStatus_t status);
typedef void (*amdtp_reply_func_t)(eAmdtpStatus_t status, uint8_t *data, uint16_t len);
typedef void (*amdtp_packet_handler_func_t)(eAmdtpPktType_t type, uint16_t len, uint8_t *buf);
typedef eAmdtpStatus_t (*amdtp_ack_sender_func_t)(eAmdtpPktType_t type, BOOLEAN encrypted, BOOLEAN enableACK, uint8_t *buf, uint16_t len);
typedef void (*amdtp_data_sender_func_t)(uint8_t *buf, uint16_t len);
typedef struct
{
eAmdtpState_t txState;
eAmdtpState_t rxState;
amdtpPacket_t rxPkt;
amdtpPacket_t txPkt;
amdtpPacket_t ackPkt;
uint8_t txPktSn; // data packet serial number for Tx
uint8_t lastRxPktSn; // last received data packet serial number
uint16_t attMtuSize;
BT_timer_handle timeoutTimer; // timeout timer after DTP update done
uint8_t txTimeout; // timeout in second unit
amdtpRecvCback_t recvCback; // application callback for data reception
amdtpTransCback_t transCback; // application callback for tx complete status
amdtp_data_sender_func_t data_sender_func;
amdtp_ack_sender_func_t ack_sender_func;
}
amdtpCb_t;
//*****************************************************************************
//
// function definitions
//
//*****************************************************************************
void
AmdtpBuildPkt(amdtpCb_t *amdtpCb, eAmdtpPktType_t type, BOOLEAN encrypted, BOOLEAN enableACK, uint8_t *buf, uint16_t len);
eAmdtpStatus_t
AmdtpReceivePkt(amdtpCb_t *amdtpCb, amdtpPacket_t *pkt, uint16_t len, uint8_t *pValue);
void
AmdtpSendReply(amdtpCb_t *amdtpCb, eAmdtpStatus_t status, uint8_t *data, uint16_t len);
void
AmdtpSendControl(amdtpCb_t *amdtpCb, eAmdtpControl_t control, uint8_t *data, uint16_t len);
void
AmdtpSendPacketHandler(amdtpCb_t *amdtpCb);
void
AmdtpPacketHandler(amdtpCb_t *amdtpCb, eAmdtpPktType_t type, uint16_t len, uint8_t *buf);
void
resetPkt(amdtpPacket_t *pkt);
#endif // AMDTP_COMMON_H
@@ -0,0 +1,554 @@
//*****************************************************************************
//
// appl_amdtps.c
//! @file
//
//*****************************************************************************
//*****************************************************************************
//
// Copyright (c) 2020, Ambiq Micro
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// 3. Neither the name of the copyright holder nor the names of its
// contributors may be used to endorse or promote products derived from this
// software without specific prior written permission.
//
// Third party software included in this distribution is subject to the
// additional license terms as defined in the /docs/licenses directory.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 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.
//
// This is part of revision 2.4.2 of the AmbiqSuite Development Package.
//
//*****************************************************************************
/**
* \file appl_amdtps.c
*
* This file contains the AMDTP application.
* Sample applications detailed below:
* a. The Sensor, as defined by the Sepcification plays the GAP Peripheral
* role.
* b. The Sensor application has following sevice records:
* - GAP
* - GATT
* - Battery
* - Device Information and
* - AMDTP
* [NOTE]: Please see gatt_db.c for more details of the record.
* c. appl_manage_transfer routine takes care of handling peer
* configuration. This handling would be needed:
* - When Peer Configures Measurement Transfer by writting to the
* Characteristic Client Configuration of AMOTA Tx.
* - Subsequent reconnection with bonded device that had already
* configured the device for transfer. Please note it is mandatory
* for GATT Servers to remember the configurations of bonded GATT
* clients.
* In order to ensure the above mentioned configurations are correctly
* handled, the routine, appl_manage_transfer, is therefore called from:
* - gatt_db_amotas_handler and
* - appl_amdtps_connect
* [NOTE]: If link does not have the needed secruity for the service,
* transfer will not be initiated.
*/
/* --------------------------------------------- Header File Inclusion */
#include "appl.h"
#include "am_mcu_apollo.h"
#include "am_bsp.h"
#include "am_util.h"
#ifdef AMDTPS
//*****************************************************************************
//
// Global variables
//
//*****************************************************************************
uint8_t rxPktBuf[AMDTP_PACKET_SIZE];
uint8_t txPktBuf[AMDTP_PACKET_SIZE];
uint8_t ackPktBuf[20];
#if defined(AMDTPS_RXONLY) || defined(AMDTPS_RX2TX)
static int totalLen = 0;
#endif
//*****************************************************************************
//
// Macro definitions
//
//*****************************************************************************
/* Control block */
static struct
{
BOOLEAN txReady; // TRUE if ready to send notifications
AmdtpsCfg_t cfg; // configurable parameters
amdtpCb_t core;
}
amdtpsCb;
/* --------------------------------------------- Static Global Variables */
static GATT_DB_HANDLE appl_amdtps_handle;
static ATT_ATTR_HANDLE appl_tx_hndl;
static ATT_ATTR_HANDLE appl_ack_hndl;
/* --------------------------------------------- Functions */
static bool sendDataContinuously = false;
static uint32_t counter = 0;
static void AmdtpsSendTestData(void)
{
uint8_t data[236] = {0};
eAmdtpStatus_t status;
sendDataContinuously = true;
*((uint32_t*)&(data[0])) = counter;
status = AmdtpsSendPacket(AMDTP_PKT_TYPE_DATA, false, true, data, sizeof(data));
if (status != AMDTP_STATUS_SUCCESS)
{
AMDTP_TRC("[AMDTP]: AmdtpsSendTestData() failed, status = %d\n", status);
}
else
{
counter++;
}
}
void amdtpsDtpRecvCback(uint8_t * buf, uint16_t len)
{
if (buf[0] == 1)
{
AMDTP_TRC("[AMDTP]: send test data\n");
AmdtpsSendTestData();
}
else if (buf[0] == 2)
{
AMDTP_TRC("[AMDTP]: send test data stop\n");
sendDataContinuously = false;
}
}
void amdtpsDtpTransCback(eAmdtpStatus_t status)
{
#ifdef AMDTP_DEBUG_ON
AMDTP_TRC("[AMDTP]: amdtpDtpTransCback =%d\n", status);
#endif
if (status == AMDTP_STATUS_SUCCESS && sendDataContinuously)
{
AmdtpsSendTestData();
}
}
void appl_amdtps_init(void)
{
appl_amdtp_server_reinitialize();
}
void appl_amdtps_connect(APPL_HANDLE * appl_handle)
{
ATT_VALUE value;
UINT16 cli_cnfg;
cli_cnfg = 0;
appl_amdtps_handle.device_id = APPL_GET_DEVICE_HANDLE((*appl_handle));
appl_amdtps_handle.char_id = GATT_CHAR_AMDTP_TX;
appl_amdtps_handle.service_id = GATT_SER_AMDTP_INST;
BT_gatt_db_get_char_val_hndl(&appl_amdtps_handle, &appl_tx_hndl);
BT_gatt_db_get_char_cli_cnfg(&appl_amdtps_handle, &value);
BT_UNPACK_LE_2_BYTE (&cli_cnfg, value.val);
appl_amdtps_handle.char_id = GATT_CHAR_AMDTP_ACK;
BT_gatt_db_get_char_val_hndl(&appl_amdtps_handle, &appl_ack_hndl);
BT_gatt_db_get_char_cli_cnfg(&appl_amdtps_handle, &value);
BT_UNPACK_LE_2_BYTE (&cli_cnfg, value.val);
AMDTP_TRC (
"[APPL]: Fetched Client Configuration (0x%04X) for Device (0x%02X)\n",
cli_cnfg, APPL_GET_DEVICE_HANDLE((*appl_handle)));
appl_manage_trasnfer(appl_amdtps_handle, cli_cnfg);
}
void appl_manage_trasnfer(GATT_DB_HANDLE handle, UINT16 config)
{
APPL_HANDLE appl_handle;
API_RESULT retval;
UCHAR security, ekey_size;
AMDTP_TRC("[AMDTP]: appl_manage_trasnfer+ \n");
/* Get required security for service */
/* Get required security level */
BT_gatt_db_get_service_security (&handle, &security);
/* Get required encryption key size */
BT_gatt_db_get_service_enc_key_size (&handle, &ekey_size);
/* Verify if security requirements are available with the link */
retval = appl_smp_assert_security
(
&handle.device_id,
security,
ekey_size
);
/* Security requirements satisfied? */
if (API_SUCCESS != retval)
{
/* No. Return */
return;
}
/* Security requirements satisfied, go ahead with data transfer */
retval = appl_get_handle_from_device_handle(handle.device_id, &appl_handle);
if (API_SUCCESS != retval)
{
return;
}
if (GATT_CLI_CNFG_NOTIFICATION == config)
{
amdtpsCb.txReady = true;
amdtpsCb.core.txState = AMDTP_STATE_TX_IDLE;
AMDTP_TRC("[AMDTP]: notify registered \n");
#if defined(AMDTPS_TXTEST)
counter = 0;
AmdtpsSendTestData(); //fixme
#endif
}
else if (GATT_CLI_CNFG_DEFAULT == config)
{
amdtpsCb.txReady = false;
AMDTP_TRC("[AMDTP]: notify unregistered \n");
}
else
{
/* Incorrect Configuration */
}
}
//*****************************************************************************
//
// Send Notification to Client
//
//*****************************************************************************
static void amdtpsSendData(uint8_t *buf, uint16_t len)
{
ATT_HANDLE_VALUE_PAIR hndl_val_param;
API_RESULT retval;
APPL_HANDLE appl_handle;
#ifdef AMDTP_DEBUG_ON
AMDTP_TRC("Sending Tx On Handle 0x%04X\n", appl_tx_hndl);
#endif
appl_get_handle_from_device_handle (appl_amdtps_handle.device_id, &appl_handle);
hndl_val_param.handle = appl_tx_hndl;
hndl_val_param.value.val = buf;
hndl_val_param.value.len = len;
retval = BT_att_send_hndl_val_ntf
(
&APPL_GET_ATT_INSTANCE(appl_handle),
&hndl_val_param
);
if (API_SUCCESS != retval)
{
AMDTP_ERR( "[** ERR **]: Failed to send, reason 0x%04X", retval);
}
}
static eAmdtpStatus_t
amdtpsSendAck(eAmdtpPktType_t type, BOOLEAN encrypted, BOOLEAN enableACK, uint8_t *buf, uint16_t len)
{
ATT_HANDLE_VALUE_PAIR hndl_val_param;
API_RESULT retval;
APPL_HANDLE appl_handle;
AmdtpBuildPkt(&amdtpsCb.core, type, encrypted, enableACK, buf, len);
#ifdef AMDTP_DEBUG_ON
AMDTP_TRC("Sending Ack On Handle 0x%04X\n", appl_ack_hndl);
#endif
/* send notification */
appl_get_handle_from_device_handle (appl_amdtps_handle.device_id, &appl_handle);
hndl_val_param.handle = appl_ack_hndl;
hndl_val_param.value.val = amdtpsCb.core.ackPkt.data;
hndl_val_param.value.len = amdtpsCb.core.ackPkt.len;
retval = BT_att_send_hndl_val_ntf
(
&APPL_GET_ATT_INSTANCE(appl_handle),
&hndl_val_param
);
if (API_SUCCESS != retval)
{
AMDTP_ERR( "[** ERR **]: Failed to send measurement, reason 0x%04X", retval);
return AMDTP_STATUS_TX_NOT_READY;
}
return AMDTP_STATUS_SUCCESS;
}
//*****************************************************************************
//
// Timer Expiration handler
//
//*****************************************************************************
void amdtps_timeout_timer_expired(void *data, UINT16 datalen)
{
API_RESULT retval = API_SUCCESS;
uint8_t ack[1];
ack[0] = amdtpsCb.core.txPktSn;
AMDTP_TRC("amdtps tx timeout, txPktSn = %d\n", amdtpsCb.core.txPktSn);
AmdtpSendControl(&amdtpsCb.core, AMDTP_CONTROL_RESEND_REQ, ack, 1);
// fire a timer for receiving an AMDTP_STATUS_RESEND_REPLY ACK
if (BT_TIMER_HANDLE_INIT_VAL != amdtpsCb.core.timeoutTimer)
{
retval = BT_stop_timer (amdtpsCb.core.timeoutTimer);
AMDTP_TRC (
"[AMDTP]: Stopping Timer with result 0x%04X, timer handle %p\n",
retval, amdtpsCb.core.timeoutTimer);
amdtpsCb.core.timeoutTimer = BT_TIMER_HANDLE_INIT_VAL;
}
retval = BT_start_timer
(
&amdtpsCb.core.timeoutTimer,
amdtpsCb.core.txTimeout,
amdtps_timeout_timer_expired,
NULL,
0
);
AMDTP_TRC (
"[AMDTP]: Started Timer with result 0x%04X, timer handle %p\n",
retval, amdtpsCb.core.timeoutTimer);
}
void amdtpsHandleValueCnf(
APPL_HANDLE * appl_handle,
UCHAR * event_data,
UINT16 event_datalen
)
{
ATT_ATTR_HANDLE attr_handle;
BT_UNPACK_LE_2_BYTE(&attr_handle, event_data);
#ifdef AMDTP_DEBUG_ON
AMDTP_TRC("appl_handle 0x%x attr_handle = 0x%x\n", *appl_handle, attr_handle);
#endif
#if !defined(AMDTPS_RXONLY) && !defined(AMDTPS_RX2TX)
if ( attr_handle == appl_tx_hndl )
{
amdtpsCb.txReady = true;
// process next data
AmdtpSendPacketHandler(&amdtpsCb.core);
#ifdef AMDTPS_TXTEST
// fixme when last packet, continue to send next one.
if (amdtpsCb.core.txState == AMDTP_STATE_WAITING_ACK)
{
uint8_t temp[3];
temp[0] = AMDTP_STATUS_SUCCESS;
AmdtpPacketHandler(&amdtpsCb.core, AMDTP_PKT_TYPE_ACK, 3, temp);
}
#endif
}
#endif
}
void amdtps_mtu_update(APPL_HANDLE * appl_handle, UINT16 t_mtu)
{
UINT16 mtu = 0;
BT_att_access_mtu(&APPL_GET_ATT_INSTANCE(*appl_handle),
&mtu);
AMDTP_TRC("appl_handle 0x%x t_mtu = %d %d\n", *appl_handle, t_mtu, mtu);
}
void appl_amdtp_server_reinitialize(void)
{
API_RESULT retval = API_SUCCESS;
memset(&amdtpsCb, 0, sizeof(amdtpsCb));
amdtpsCb.txReady = false;
amdtpsCb.core.txState = AMDTP_STATE_INIT;
amdtpsCb.core.rxState = AMDTP_STATE_RX_IDLE;
amdtpsCb.core.lastRxPktSn = 0;
amdtpsCb.core.txPktSn = 0;
resetPkt(&amdtpsCb.core.rxPkt);
amdtpsCb.core.rxPkt.data = rxPktBuf;
resetPkt(&amdtpsCb.core.txPkt);
amdtpsCb.core.txPkt.data = txPktBuf;
resetPkt(&amdtpsCb.core.ackPkt);
amdtpsCb.core.ackPkt.data = ackPktBuf;
amdtpsCb.core.recvCback = amdtpsDtpRecvCback;
amdtpsCb.core.transCback = amdtpsDtpTransCback;
amdtpsCb.core.data_sender_func = amdtpsSendData;
amdtpsCb.core.ack_sender_func = amdtpsSendAck;
amdtpsCb.core.txTimeout = TX_TIMEOUT_DEFAULT;
if (BT_TIMER_HANDLE_INIT_VAL != amdtpsCb.core.timeoutTimer)
{
retval = BT_stop_timer (amdtpsCb.core.timeoutTimer);
AMDTP_TRC (
"[AMDTP]: Stopping Timer with result 0x%04X, timer handle %p\n",
retval, amdtpsCb.core.timeoutTimer);
amdtpsCb.core.timeoutTimer = BT_TIMER_HANDLE_INIT_VAL;
}
#if defined(AMDTPS_RXONLY) || defined(AMDTPS_RX2TX)
AMDTP_TRC("*** RECEIVED TOTAL %d ***\n", totalLen);
totalLen = 0;
#endif
}
API_RESULT appl_amdtps_write_cback
(
GATT_DB_HANDLE * handle,
ATT_VALUE * value
)
{
API_RESULT retval = API_SUCCESS;
eAmdtpStatus_t status = AMDTP_STATUS_UNKNOWN_ERROR;
amdtpPacket_t *pkt = NULL;
#if 0
uint16_t i = 0;
AMDTP_TRC("============= data arrived start ===============\n");
for (i = 0; i < value->len; i++)
{
AMDTP_TRC("%x\t", value->val[i]);
}
AMDTP_TRC("============= data arrived end ===============\n");
#endif
if (GATT_CHAR_AMDTP_RX == handle->char_id)
{
#if defined(AMDTPS_RX2TX)
amdtpsSendData(value->val, value->len);
#endif
#if defined(AMDTPS_RXONLY) || defined(AMDTPS_RX2TX)
totalLen += value->len;
AMDTP_TRC("received data len %d, total %d\n", value->len, totalLen);
return API_SUCCESS;
#else /* RXONLY && RX2TX */
status = AmdtpReceivePkt(&amdtpsCb.core, &amdtpsCb.core.rxPkt, value->len, value->val);
#endif
}
else if (GATT_CHAR_AMDTP_ACK == handle->char_id)
{
status = AmdtpReceivePkt(&amdtpsCb.core, &amdtpsCb.core.ackPkt, value->len, value->val);
}
if (status == AMDTP_STATUS_RECEIVE_DONE)
{
if (GATT_CHAR_AMDTP_RX == handle->char_id)
{
pkt = &amdtpsCb.core.rxPkt;
}
else if (GATT_CHAR_AMDTP_ACK == handle->char_id)
{
pkt = &amdtpsCb.core.ackPkt;
}
AmdtpPacketHandler(&amdtpsCb.core, (eAmdtpPktType_t)pkt->header.pktType, pkt->len - AMDTP_CRC_SIZE_IN_PKT, pkt->data);
}
return retval;
}
//*****************************************************************************
//
//! @brief Send data to Client via notification
//!
//! @param type - packet type
//! @param encrypted - is packet encrypted
//! @param enableACK - does client need to response
//! @param buf - data
//! @param len - data length
//!
//! @return status
//
//*****************************************************************************
eAmdtpStatus_t
AmdtpsSendPacket(eAmdtpPktType_t type, BOOLEAN encrypted, BOOLEAN enableACK, uint8_t *buf, uint16_t len)
{
//
// Check if ready to send notification
//
if ( !amdtpsCb.txReady )
{
//set in callback amdtpsHandleValueCnf
AMDTP_TRC("data sending failed, not ready for notification.\n", NULL);
return AMDTP_STATUS_TX_NOT_READY;
}
//
// Check if the service is idle to send
//
if ( amdtpsCb.core.txState != AMDTP_STATE_TX_IDLE )
{
AMDTP_TRC("data sending failed, tx state = %d\n", amdtpsCb.core.txState);
return AMDTP_STATUS_BUSY;
}
//
// Check if data length is valid
//
if ( len > AMDTP_MAX_PAYLOAD_SIZE )
{
AMDTP_TRC("data sending failed, exceed maximum payload, len = %d.\n", len);
return AMDTP_STATUS_INVALID_PKT_LENGTH;
}
AmdtpBuildPkt(&amdtpsCb.core, type, encrypted, enableACK, buf, len);
// send packet
AmdtpSendPacketHandler(&amdtpsCb.core);
return AMDTP_STATUS_SUCCESS;
}
#endif /* AMDTPS */
@@ -0,0 +1,102 @@
//*****************************************************************************
//
// appl_amdtps.h
//! @file
//
//*****************************************************************************
//*****************************************************************************
//
// Copyright (c) 2020, Ambiq Micro
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// 3. Neither the name of the copyright holder nor the names of its
// contributors may be used to endorse or promote products derived from this
// software without specific prior written permission.
//
// Third party software included in this distribution is subject to the
// additional license terms as defined in the /docs/licenses directory.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 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.
//
// This is part of revision 2.4.2 of the AmbiqSuite Development Package.
//
//*****************************************************************************
/**
* \file appl_amdtps.h
*
* Application Header File for AMDTPS.
*/
#ifndef _H_APPL_AMDTPS_
#define _H_APPL_AMDTPS_
/* ----------------------------------------- Header File Inclusion */
#include "BT_api.h"
#include "BT_gatt_db_api.h"
#include "gatt_db.h"
#include "appl.h"
#include "amdtp_common.h"
//*****************************************************************************
//
// Macro definitions
//
//*****************************************************************************
/*! Configurable parameters */
typedef struct
{
//! Short description of each member should go here.
uint32_t reserved;
}
AmdtpsCfg_t;
/* --------------------------------------------- Functions */
void appl_amdtps_init(void);
void appl_manage_trasnfer(GATT_DB_HANDLE handle, UINT16 config);
void appl_amdtps_connect(DEVICE_HANDLE * dq_handle);
void appl_amdtp_server_reinitialize(void);
API_RESULT appl_amdtps_write_cback(GATT_DB_HANDLE *handle, ATT_VALUE *value);
eAmdtpStatus_t AmdtpsSendPacket(eAmdtpPktType_t type, BOOLEAN encrypted, BOOLEAN enableACK, uint8_t *buf, uint16_t len);
void amdtpsHandleValueCnf( APPL_HANDLE * appl_handle, UCHAR * event_data, UINT16 event_datalen);
void amdtps_mtu_update(APPL_HANDLE * appl_handle, UINT16 t_mtu);
/* Profile handling */
#define APPL_PROFILE_INIT(...) appl_amdtps_init()
#define APPL_PROFILE_CONNECT(x) appl_amdtps_connect(x)
#define APPL_SEND_MEASUREMENT(x)
#define APPL_PROFILE_DISCONNECT_HANDLER(x) appl_amdtp_server_reinitialize()
#define GATT_DB_PROFILE_HANDLER gatt_db_amdtps_handler
#define APPL_PROFILE_HVN_NTF_COMPLETE_HANDLER(x, y, z) amdtpsHandleValueCnf(x, y, z)
#define APPL_PROFILE_HVN_IND_COMPLETE_HANDLER(x, y, z) amdtpsHandleValueCnf(x, y, z)
#define APPL_PROFILE_MTU_UPDT_COMPLETE_HANDLER(x, y) amdtps_mtu_update(x, y)
#define APPL_USE_IDLE_TIMER
#define APPL_IDLE_TIMEOUT 30
#endif /* _H_APPL_AMDTPS_ */
@@ -0,0 +1,221 @@
//*****************************************************************************
//
// appl_gap_config_params.c
//! @file
//
//*****************************************************************************
//*****************************************************************************
//
// Copyright (c) 2020, Ambiq Micro
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// 3. Neither the name of the copyright holder nor the names of its
// contributors may be used to endorse or promote products derived from this
// software without specific prior written permission.
//
// Third party software included in this distribution is subject to the
// additional license terms as defined in the /docs/licenses directory.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 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.
//
// This is part of revision 2.4.2 of the AmbiqSuite Development Package.
//
//*****************************************************************************
/**
* \file appl_gap_config_params.c
*
* This file contains GAP Configuration Parameters used by the application.
*/
/* --------------------------------------------- Header File Inclusion */
#include "appl_gap.h"
#ifdef AMDTPS
/* --------------------------------------------- External Global Variables */
/* --------------------------------------------- Exported Global Variables */
/* --------------------------------------------- Static Global Variables */
#if ((defined APPL_GAP_BROADCASTER_SUPPORT) || (defined APPL_GAP_PERIPHERAL_SUPPORT))
/** Advertisement Data Options */
const APPL_GAP_ADV_DATA appl_gap_adv_data[APPL_GAP_MAX_ADV_DATA_OPTIONS] =
{
/* GAP Advertisement Parameters */
{
{
/**
* Flags:
* 0x01: LE Limited Discoverable Mode
* 0x02: LE General Discoverable Mode
* 0x04: BR/EDR Not Supported
* 0x08: Simultaneous LE and BR/EDR to Same Device
* Capable (Controller)
* 0x10: Simultaneous LE and BR/EDR to Same Device
* Capable (Host)
*/
0x02, 0x01,
(BT_AD_FLAGS_LE_GENERAL_DISC_MODE | BT_AD_FLAGS_LE_BR_EDR_SUPPORT),
/**
* Service UUID List:
* Battery Service (0x180F)
* DeviceInformation Service (0x180A)
* Heart Rate Service (0x180D)
*/
0x07, 0x03, 0x0F, 0x18, 0x0A, 0x18, 0x0D, 0x18,
/**
* Shortened Device Name: Mindtree
*/
0x09, 0x08, 0x4D, 0x69, 0x6E, 0x64, 0x74, 0x72, 0x65, 0x65
},
21
}
};
/* Advertisement parameters options */
const APPL_GAP_ADV_PARAM appl_gap_adv_param[APPL_GAP_MAX_ADV_PARAM_OPTIONS] =
{
/* 0 - Normal Advertising Params */
{
32,
32,
7,
0
},
/* 1 - Fast Connection Advertising Params */
{
32,
48,
7,
0
},
/* 2 - Low Power Advertising Params */
{
1600,
4000,
7,
0
}
};
/* Advertisement Table */
APPL_GAP_ADV_INFO appl_gap_adv_table =
{
appl_gap_adv_data,
appl_gap_adv_param,
APPL_GAP_ADV_IDLE
};
#endif /* APPL_GAP_BROADCASTER || APPL_GAP_PERIPHERAL_SUPPORT */
#if ((defined APPL_GAP_OBSERVER_SUPPORT) || (defined APPL_GAP_CENTRAL_SUPPORT))
/* Scan Parameters Option */
const APPL_GAP_SCAN_PARAM appl_gap_scan_param[APPL_GAP_MAX_SCAN_PARAM_OPTIONS] =
{
/* Normal Scan Params */
{
32,
7,
0
},
/* Fast Connection Scan Params */
{
48,
7,
0
},
/* Low Power Scan Params */
{
4000,
7,
0
}
};
/* Scan Table */
APPL_GAP_SCAN_INFO appl_gap_scan_table =
{
appl_gap_scan_param,
APPL_GAP_SCAN_IDLE
};
#endif /* APPL_GAP_OBSERVER_SUPPORT || APPL_GAP_CENTRAL_SUPPORT */
#ifdef APPL_GAP_CENTRAL_SUPPORT
/* Connection Parameters Options */
const APPL_GAP_CONN_PARAM appl_gap_conn_param[APPL_GAP_MAX_CONN_PARAM_OPTIONS] =
{
{
4,
4,
0,
40,
56,
0,
955,
32,
32
}
};
/* GAP Connection Table */
APPL_GAP_CONN_INFO appl_gap_conn_table =
{
appl_gap_conn_param,
APPL_GAP_CONN_IDLE
};
#endif /* APPL_GAP_CENTRAL_SUPPORT */
#endif /* AMDTPS */
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,161 @@
//*****************************************************************************
//
// gatt_db.h
//! @file
//
//*****************************************************************************
//*****************************************************************************
//
// Copyright (c) 2020, Ambiq Micro
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// 3. Neither the name of the copyright holder nor the names of its
// contributors may be used to endorse or promote products derived from this
// software without specific prior written permission.
//
// Third party software included in this distribution is subject to the
// additional license terms as defined in the /docs/licenses directory.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 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.
//
// This is part of revision 2.4.2 of the AmbiqSuite Development Package.
//
//*****************************************************************************
/**
* \file gatt_db.h
*/
#ifndef _H_GATT_DB_
#define _H_GATT_DB_
/**
* addgroup gatt_db_module
*/
/**
* defgroup gatt_db_tuneable_param Tuneable Parameters
* {
* This section defines the Tuneable Constants of Data Base Module.
*/
/** Number of Characteristics in the data base */
#define GATT_CHARACTERISTIC_COUNT 16
/** Number of Services in the data base */
#define GATT_SERVICE_COUNT 5
/** Number of Characteristics that are configurable by the client */
#define GATT_DB_MAX_CONFIGUREABLE_CHAR 4
/** Maximum Length of any Characteristic Value/Descriptor */
#define GATT_DB_MAX_VAL_LENGTH 32
#define GATT_VALUE_ARRAY_SIZE 1
#define GATT_CONST_VALUE_ARRAY_SIZE 245
#define GATT_DB_PEER_VALUE_ARRAY_SIZE 8
#define GATT_DB_MAX_ATTRIBUTES 43
#define GATT_UUID_ARRAY_SIZE 118
#define GATT_DB_MAX_TYPE_COUNT 25
#define GATT_DB_MAX_PEER_CONFIGURATION \
(GATT_DB_PEER_VALUE_ARRAY_SIZE * BT_MAX_DEVICE_QUEUE_SIZE)
/** \} */
/** Service Instance Reference */
/** GAP Service */
#define GATT_SER_GAP_INST 0
/** GATT Service */
#define GATT_SER_GATT_INST 1
/** Battery Service */
#define GATT_SER_BATTERY_INST 2
/** DeviceInformation Service */
#define GATT_SER_DEV_INFO_INST 3
/** AMDTP Service */
#define GATT_SER_AMDTP_INST 4
/** Characteristic Instance Reference */
/** DeviceName */
#define GATT_CHAR_DEV_NAME_INST 0
/** Appearance */
#define GATT_CHAR_APPEARANCE_INST 1
/** Service Changed */
#define GATT_CHAR_SER_CHNGD_INST 2
/** BatteryLevel */
#define GATT_CHAR_BATTERY_LVL_INST 3
/** ManufacturerName */
#define GATT_CHAR_MAN_NAME_INST 4
/** ModelNumber */
#define GATT_CHAR_MODEL_NO_INST 5
/** SerialNumber */
#define GATT_CHAR_SL_NO_INST 6
/** FirmwareRevision */
#define GATT_CHAR_FW_REV_INST 7
/** HardwareRevision */
#define GATT_CHAR_HW_REV_INST 8
/** SoftwareRevision */
#define GATT_CHAR_SW_REV_INST 9
/** SystemId */
#define GATT_CHAR_SYS_ID_INST 10
/** RegCertDataList */
#define GATT_CHAR_REG_CERT_DATA_INST 11
/** PnPID */
#define GATT_CHAR_PNP_ID_INST 12
/** AMDTP Rx */
#define GATT_CHAR_AMDTP_RX 13
/** AMDTP Tx */
#define GATT_CHAR_AMDTP_TX 14
/** AMDTP Ack */
#define GATT_CHAR_AMDTP_ACK 15
#endif /* _H_GATT_DB_ */
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,113 @@
//*****************************************************************************
//
// appl_amota.h
//! @file
//!
//! @brief Application Header File for AMOTA.
//
//*****************************************************************************
//*****************************************************************************
//
// Copyright (c) 2020, Ambiq Micro
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// 3. Neither the name of the copyright holder nor the names of its
// contributors may be used to endorse or promote products derived from this
// software without specific prior written permission.
//
// Third party software included in this distribution is subject to the
// additional license terms as defined in the /docs/licenses directory.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 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.
//
// This is part of revision 2.4.2 of the AmbiqSuite Development Package.
//
//*****************************************************************************
/**
* \file appl_amota.h
*
* Application Header File for AMOTA.
*/
#ifndef _H_APPL_AMOTA_
#define _H_APPL_AMOTA_
/* ----------------------------------------- Header File Inclusion */
#include "BT_api.h"
#include "BT_gatt_db_api.h"
#include "gatt_db.h"
#include "appl.h"
// enable debug print for AMOTA profile
// #define AMOTA_DEBUG_ON
/* --------------------------------------------- Global Definitions */
#define AMOTA_PACKET_SIZE (512 + 16) // Bytes
#define AMOTA_LENGTH_SIZE_IN_PKT 2
#define AMOTA_CMD_SIZE_IN_PKT 1
#define AMOTA_CRC_SIZE_IN_PKT 4
#define AMOTA_HEADER_SIZE_IN_PKT AMOTA_LENGTH_SIZE_IN_PKT + AMOTA_CMD_SIZE_IN_PKT
#define AMOTA_FW_HEADER_SIZE 44
#define AMOTA_FW_STORAGE_INTERNAL 0
#define AMOTA_FW_STORAGE_EXTERNAL 1
/* ----------------------------------------- Data Types/ Structures */
/*! Configurable parameters */
typedef struct
{
//! Short description of each member should go here.
uint32_t reserved;
}
AmotasCfg_t;
/* --------------------------------------------- Functions */
void appl_amotas_init(void);
void appl_manage_trasnfer(GATT_DB_HANDLE handle, UINT16 config);
void appl_amotas_connect(DEVICE_HANDLE * dq_handle);
void appl_amotas_send_data(UCHAR *data, UINT16 len);
void appl_amotas_disconnect(void);
API_RESULT appl_amotas_write_cback(GATT_DB_HANDLE *handle, ATT_VALUE *value);
void amota_mtu_update(APPL_HANDLE * appl_handle, UINT16 t_mtu);
/* Profile handling */
#define APPL_PROFILE_INIT(...) appl_amotas_init()
#define APPL_PROFILE_CONNECT(x) appl_amotas_connect(x)
#define APPL_SEND_MEASUREMENT(x) //appl_send_amotas_measurement(x)
#define APPL_PROFILE_DISCONNECT_HANDLER(x) appl_amotas_disconnect()
#define GATT_DB_PROFILE_HANDLER gatt_db_amotas_handler
#define APPL_PROFILE_HVN_NTF_COMPLETE_HANDLER(x, y, z)
#define APPL_PROFILE_HVN_IND_COMPLETE_HANDLER(x, y, z)
#define APPL_PROFILE_MTU_UPDT_COMPLETE_HANDLER(x, y) amota_mtu_update(x, y)
#define APPL_USE_IDLE_TIMER
#define APPL_IDLE_TIMEOUT 30
#endif /* _H_APPL_AMOTA_ */
@@ -0,0 +1,223 @@
//*****************************************************************************
//
// appl_gap_config_params.c
//! @file
//!
//! @brief This file contains GAP Configuration Parameters used by the application.
//
//*****************************************************************************
//*****************************************************************************
//
// Copyright (c) 2020, Ambiq Micro
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// 3. Neither the name of the copyright holder nor the names of its
// contributors may be used to endorse or promote products derived from this
// software without specific prior written permission.
//
// Third party software included in this distribution is subject to the
// additional license terms as defined in the /docs/licenses directory.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 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.
//
// This is part of revision 2.4.2 of the AmbiqSuite Development Package.
//
//*****************************************************************************
/**
* \file appl_gap_config_params.c
*
* This file contains GAP Configuration Parameters used by the application.
*/
/* --------------------------------------------- Header File Inclusion */
#include "appl_gap.h"
#ifdef AMOTAS
/* --------------------------------------------- External Global Variables */
/* --------------------------------------------- Exported Global Variables */
/* --------------------------------------------- Static Global Variables */
#if ((defined APPL_GAP_BROADCASTER_SUPPORT) || (defined APPL_GAP_PERIPHERAL_SUPPORT))
/** Advertisement Data Options */
const APPL_GAP_ADV_DATA appl_gap_adv_data[APPL_GAP_MAX_ADV_DATA_OPTIONS] =
{
/* GAP Advertisement Parameters */
{
{
/**
* Flags:
* 0x01: LE Limited Discoverable Mode
* 0x02: LE General Discoverable Mode
* 0x04: BR/EDR Not Supported
* 0x08: Simultaneous LE and BR/EDR to Same Device
* Capable (Controller)
* 0x10: Simultaneous LE and BR/EDR to Same Device
* Capable (Host)
*/
0x02, 0x01,
(BT_AD_FLAGS_LE_GENERAL_DISC_MODE | BT_AD_FLAGS_LE_BR_EDR_SUPPORT),
/**
* Service UUID List:
* Battery Service (0x180F)
* DeviceInformation Service (0x180A)
* Heart Rate Service (0x180D)
*/
0x07, 0x03, 0x0F, 0x18, 0x0A, 0x18, 0x0D, 0x18,
/**
* Shortened Device Name: Mindtree
*/
0x09, 0x08, 0x4D, 0x69, 0x6E, 0x64, 0x74, 0x72, 0x65, 0x65
},
21
}
};
/* Advertisement parameters options */
const APPL_GAP_ADV_PARAM appl_gap_adv_param[APPL_GAP_MAX_ADV_PARAM_OPTIONS] =
{
/* 0 - Normal Advertising Params */
{
32,
32,
7,
0
},
/* 1 - Fast Connection Advertising Params */
{
32,
48,
7,
0
},
/* 2 - Low Power Advertising Params */
{
32,
32,
7,
0
}
};
/* Advertisement Table */
APPL_GAP_ADV_INFO appl_gap_adv_table =
{
appl_gap_adv_data,
appl_gap_adv_param,
APPL_GAP_ADV_IDLE
};
#endif /* APPL_GAP_BROADCASTER || APPL_GAP_PERIPHERAL_SUPPORT */
#if ((defined APPL_GAP_OBSERVER_SUPPORT) || (defined APPL_GAP_CENTRAL_SUPPORT))
/* Scan Parameters Option */
const APPL_GAP_SCAN_PARAM appl_gap_scan_param[APPL_GAP_MAX_SCAN_PARAM_OPTIONS] =
{
/* Normal Scan Params */
{
32,
7,
0
},
/* Fast Connection Scan Params */
{
48,
7,
0
},
/* Low Power Scan Params */
{
4000,
7,
0
}
};
/* Scan Table */
APPL_GAP_SCAN_INFO appl_gap_scan_table =
{
appl_gap_scan_param,
APPL_GAP_SCAN_IDLE
};
#endif /* APPL_GAP_OBSERVER_SUPPORT || APPL_GAP_CENTRAL_SUPPORT */
#ifdef APPL_GAP_CENTRAL_SUPPORT
/* Connection Parameters Options */
const APPL_GAP_CONN_PARAM appl_gap_conn_param[APPL_GAP_MAX_CONN_PARAM_OPTIONS] =
{
{
4,
4,
0,
40,
56,
0,
955,
32,
32
}
};
/* GAP Connection Table */
APPL_GAP_CONN_INFO appl_gap_conn_table =
{
appl_gap_conn_param,
APPL_GAP_CONN_IDLE
};
#endif /* APPL_GAP_CENTRAL_SUPPORT */
#endif /* AMOTAS */
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,161 @@
//*****************************************************************************
//
// gatt_db.h
//! @file
//!
//! @brief This section defines the Tuneable Constants of Data Base Module.
//
//*****************************************************************************
//*****************************************************************************
//
// Copyright (c) 2020, Ambiq Micro
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// 3. Neither the name of the copyright holder nor the names of its
// contributors may be used to endorse or promote products derived from this
// software without specific prior written permission.
//
// Third party software included in this distribution is subject to the
// additional license terms as defined in the /docs/licenses directory.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 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.
//
// This is part of revision 2.4.2 of the AmbiqSuite Development Package.
//
//*****************************************************************************
/**
* \file gatt_db.h
*/
#ifndef _H_GATT_DB_
#define _H_GATT_DB_
/**
* addgroup gatt_db_module
*/
/**
* defgroup gatt_db_tuneable_param Tuneable Parameters
* {
* This section defines the Tuneable Constants of Data Base Module.
*/
/** Number of Characteristics in the data base */
#define GATT_CHARACTERISTIC_COUNT 15
/** Number of Services in the data base */
#define GATT_SERVICE_COUNT 5
/** Number of Characteristics that are configurable by the client */
#define GATT_DB_MAX_CONFIGUREABLE_CHAR 3
/** Maximum Length of any Characteristic Value/Descriptor */
#define GATT_DB_MAX_VAL_LENGTH 32
#define GATT_VALUE_ARRAY_SIZE 1
#define GATT_CONST_VALUE_ARRAY_SIZE 226
#define GATT_DB_PEER_VALUE_ARRAY_SIZE 6
#define GATT_DB_MAX_ATTRIBUTES 40
#define GATT_UUID_ARRAY_SIZE 102
#define GATT_DB_MAX_TYPE_COUNT 24
#define GATT_DB_MAX_PEER_CONFIGURATION \
(GATT_DB_PEER_VALUE_ARRAY_SIZE * BT_MAX_DEVICE_QUEUE_SIZE)
/** \} */
/** Service Instance Reference */
/** GAP Service */
#define GATT_SER_GAP_INST 0
/** GATT Service */
#define GATT_SER_GATT_INST 1
/** Battery Service */
#define GATT_SER_BATTERY_INST 2
/** DeviceInformation Service */
#define GATT_SER_DEV_INFO_INST 3
/** AMOTA Service */
#define GATT_SER_AMOTA_INST 4
/** Characteristic Instance Reference */
/** DeviceName */
#define GATT_CHAR_DEV_NAME_INST 0
/** Appearance */
#define GATT_CHAR_APPEARANCE_INST 1
/** Service Changed */
#define GATT_CHAR_SER_CHNGD_INST 2
/** BatteryLevel */
#define GATT_CHAR_BATTERY_LVL_INST 3
/** ManufacturerName */
#define GATT_CHAR_MAN_NAME_INST 4
/** ModelNumber */
#define GATT_CHAR_MODEL_NO_INST 5
/** SerialNumber */
#define GATT_CHAR_SL_NO_INST 6
/** FirmwareRevision */
#define GATT_CHAR_FW_REV_INST 7
/** HardwareRevision */
#define GATT_CHAR_HW_REV_INST 8
/** SoftwareRevision */
#define GATT_CHAR_SW_REV_INST 9
/** SystemId */
#define GATT_CHAR_SYS_ID_INST 10
/** RegCertDataList */
#define GATT_CHAR_REG_CERT_DATA_INST 11
/** PnPID */
#define GATT_CHAR_PNP_ID_INST 12
/** AMOTA Rx */
#define GATT_CHAR_AMOTA_RX 13
/** AMOTA Tx */
#define GATT_CHAR_AMOTA_TX 14
#endif /* _H_GATT_DB_ */
@@ -0,0 +1,604 @@
//*****************************************************************************
//
//! @file appl_ams.c
//!
//! @brief Provides functions for the AMS service.
//!
//
//*****************************************************************************
//*****************************************************************************
//
// Copyright (c) 2020, Ambiq Micro
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// 3. Neither the name of the copyright holder nor the names of its
// contributors may be used to endorse or promote products derived from this
// software without specific prior written permission.
//
// Third party software included in this distribution is subject to the
// additional license terms as defined in the /docs/licenses directory.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 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.
//
// This is part of revision 2.4.2 of the AmbiqSuite Development Package.
//
//*****************************************************************************
/**
* \file appl_ams.c
*
*/
/* --------------------------------------------- Header File Inclusion */
#ifdef AMS
#include "appl.h"
#include "BT_common.h"
#include "BT_hci_api.h"
#include "BT_att_api.h"
#include "BT_smp_api.h"
#include "smp_pl.h"
#include "l2cap.h"
#include "fsm_defines.h"
#include "task.h"
/* ----------------------------------------- Configuration Defines */
extern uint32_t am_util_stdio_printf(const char *pcFmt, ...);
#undef APPL_TRC
#undef APPL_ERR
#define APPL_TRC am_util_stdio_printf
#define APPL_ERR am_util_stdio_printf
/* ----------------------------------------- Macro Defines */
/**@brief Entity IDs */
typedef enum
{
AMS_ENTITY_ID_PLAYER, /** The currently active media app. Attributes for this entity include values such as its name, playback state, and playback volume. */
AMS_ENTITY_ID_QUEUE, /** The currently loaded playback queue. Attributes for this entity include values such as its size and its shuffle and repeat modes. */
AMS_ENTITY_ID_TRACK, /** The currently loaded track. Attributes for this entity include values such as its artist, title, and duration. */
} ams_entity_id_values_t;
/**@brief Player AttributeID */
typedef enum
{
AMS_PLAYER_ATTRID_NAME, /** A string containing the localized name of the app */
AMS_PLAYER_ATTRID_PLAYBACKINFO, /** PlaybackState, PlaybackRate, ElapsedTime */
AMS_PLAYER_ATTRID_VOLUME, /** A string that represents the floating point value of the volume, ranging from 0 (silent) to 1 (full volume). */
} ams_player_attribute_id_values_t;
/**@brief Queue AttributeID */
typedef enum
{
AMS_QUEUE_ATTRID_INDEX, /** A string containing the integer value of the queue index, zero-based. */
AMS_QUEUE_ATTRID_COUNT, /** A string containing the integer value of the total number of items in the queue. */
AMS_QUEUE_ATTRID_SHUFFLE, /** A string containing the integer value of the shuffle mode. */
AMS_QUEUE_ATTRID_REPEAT, /** A string containing the integer value value of the repeat mode. */
} ams_queue_attribute_id_values_t;
/**@brief Track AttributeID */
typedef enum
{
AMS_TRACK_ATTRID_ARTIST, /** A string containing the name of the artist. */
AMS_TRACK_ATTRID_ALBUM, /** A string containing the name of the album. */
AMS_TRACK_ATTRID_TITLE, /** A string containing the title of the track. */
AMS_TRACK_ATTRID_DURATION, /** A string containing the floating point value of the total duration of the track in seconds. */
} ams_track_attribute_id_values_t;
typedef enum
{
AMS_DISCONNECTED,
AMS_CONNECTED,
AMS_BONDED,
AMS_DISCOVERED,
} ams_appl_state_t;
/* ----------------------------------------- External Global Variables */
void appl_profile_operations (void);
void appl_bond_with_peer(void);
void appl_discover_AMS(void);
extern BT_DEVICE_ADDR g_bd_addr;
/* ----------------------------------------- Exported Global Variables */
/* ----------------------------------------- Static Global Variables */
DECL_STATIC UCHAR write_response = 0;
DECL_STATIC API_RESULT gResult = 0;
DECL_STATIC ams_appl_state_t appl_ams_state = AMS_DISCONNECTED;
DECL_STATIC ATT_UUID ams_service_uuid128 = {.uuid_128.value = {0xDC, 0xF8, 0x55, 0xAD, 0x02, 0xC5, 0xF4, 0x8E, 0x3A, 0x43, 0x36, 0x0F, 0x2B, 0x50, 0xD3, 0x89}};
DECL_STATIC ATT_UUID AMS_RemoteCommand_UUID = {.uuid_128.value = {0xC2, 0x51, 0xCA, 0xF7, 0x56, 0x0E, 0xDF, 0xB8, 0x8A, 0x4A, 0xB1, 0x57, 0xD8, 0x81, 0x3C, 0x9B}};
DECL_STATIC ATT_UUID AMS_EntityUpdate_UUID = {.uuid_128.value = {0x02, 0xC1, 0x96, 0xBA, 0x92, 0xBB, 0x0C, 0x9A, 0x1F, 0x41, 0x8D, 0x80, 0xCE, 0xAB, 0x7C, 0x2F}};
DECL_STATIC ATT_UUID AMS_EntityAttribute_UUID = {.uuid_128.value = {0xD7, 0xD5, 0xBB, 0x70, 0xA8, 0xA3, 0xAB, 0xA6, 0xD8, 0x46, 0xAB, 0x23, 0x8C, 0xF3, 0xB2, 0xC6}};
/* BLE Connection Handle */
//DECL_STATIC UINT16 appl_ble_connection_handle;
/** AMS Characteristic related information */
typedef struct
{
/* AMS Service */
/* Remote Command */
ATT_ATTR_HANDLE ams_remote_command_hdl;
/* Remote Command - CCC */
ATT_ATTR_HANDLE ams_remote_command_ccc_hdl;
/* Entity Update */
ATT_ATTR_HANDLE ams_entity_update_hdl;
/* Entity Update - CCC */
ATT_ATTR_HANDLE ams_entity_update_ccc_hdl;
/* Entity Attribute */
ATT_ATTR_HANDLE ams_entity_attribute_hdl;
} AMS_CHAR_INFO;
#define APPL_CLI_CNFG_VAL_LENGTH 2
DECL_STATIC AMS_CHAR_INFO ams_char_info;
#ifdef APPL_MENU_OPS
BT_DEVICE_ADDR g_peer_bd_addr;
static UCHAR ams_client_menu[] =
"\n\
\r\n\
1. Bond with peer \r\n\
\r\n\
2. Discover AMS \r\n\
\r\n\
3. Subscribe to Entity Update \r\n\
\r\n\
4. Write to Entity Update \r\n\
\r\n\
5. Write to Remote Command \r\n\
\r\n\
6. Write to Entity Attribute \r\n\
\r\n\
7. Read Entity Attribute \r\n\
\r\n\
Your Option? \0";
#endif /* APPL_MENU_OPS */
/* --------------------------------------------- Constants */
/* --------------------------------------------- Static Global Variables */
/* --------------------------------------------- Functions */
void appl_bond_with_peer(void)
{
API_RESULT retval;
/* If connection is successful, initiate bonding [Step 2(c)] */
SMP_AUTH_INFO auth;
SMP_BD_ADDR smp_peer_bd_addr;
SMP_BD_HANDLE smp_bd_handle;
APPL_TRC("\n<<appl_bond_with_peer>>\n");
auth.param = 1;
auth.bonding = 1;
auth.ekey_size = 12;
auth.security = SMP_SEC_LEVEL_1;
BT_COPY_BD_ADDR(smp_peer_bd_addr.addr, g_bd_addr.addr);
BT_COPY_TYPE(smp_peer_bd_addr.type, g_bd_addr.type);
retval = BT_smp_get_bd_handle
(
&smp_peer_bd_addr,
&smp_bd_handle
);
if (API_SUCCESS == retval)
{
retval = BT_smp_authenticate (&smp_bd_handle, &auth);
}
if (API_SUCCESS != retval)
{
APPL_TRC (
"Initiation of Authentication Failed. Reason 0x%04X\n",
retval);
}
/**
* Application will receive authentication complete event,
* in SMP Callback.
*
* Look for 'SMP_AUTHENTICATION_COMPLETE' event handling in
* 'appl_smp_callback'.
*/
}
void appl_ams_init(void)
{
appl_ams_state = AMS_DISCONNECTED;
APPL_TRC("\n\n<<appl_ams_init>>\n\n");
}
void appl_ams_connect(APPL_HANDLE * appl_handle)
{
APPL_STATE_T state = GET_APPL_STATE(*appl_handle);
if ( state == SL_0_TRANSPORT_OPERATING && appl_ams_state == AMS_DISCONNECTED )
{
appl_ams_state = AMS_CONNECTED;
APPL_TRC("\n\n<<CONNECTED>>\n\n");
}
else if ( state == SL_0_TRANSPORT_OPERATING && appl_ams_state == AMS_DISCOVERED)
{
appl_ams_state = AMS_BONDED;
APPL_TRC("\n\n<<BONDED>>\n\n");
}
else
{
appl_ams_state = AMS_DISCONNECTED;
APPL_TRC("\n\n<<DISCONNECTED>>\n\n");
}
}
void appl_search_complete(void)
{
appl_ams_state = AMS_DISCOVERED;
APPL_TRC("\n\n<<DISCOVERED>>\n\n");
}
void appl_recvice_att_event(UCHAR att_event, API_RESULT event_result)
{
if ( att_event == ATT_WRITE_RSP )
{
write_response = 1;
gResult = 0;
}
else if ( att_event == ATT_ERROR_RSP )
{
gResult = event_result;
}
}
void appl_manage_trasnfer (GATT_DB_HANDLE handle, UINT16 config)
{
APPL_TRC("\n\n<<appl_manage_trasnfer>>\n\n");
}
void appl_send_ams_measurement (APPL_HANDLE * handle)
{
APPL_TRC("\n\n<<appl_send_ams_measurement>>\n\n");
}
void appl_timer_expiry_handler (void *data, UINT16 datalen)
{
APPL_TRC("\n\n<<appl_timer_expiry_handler>>\n\n");
}
void appl_ams_server_reinitialize (void)
{
appl_ams_state = AMS_DISCONNECTED;
APPL_TRC("\n\n<<appl_ams_server_reinitialize>>\n\n");
}
void ams_mtu_update(APPL_HANDLE * appl_handle, UINT16 t_mtu)
{
UINT16 mtu = 0;
BT_att_access_mtu(&APPL_GET_ATT_INSTANCE(*appl_handle),
&mtu);
APPL_TRC("appl_handle 0x%x t_mtu = %d %d\n", *appl_handle, t_mtu, mtu);
}
/* ------------------------------- ATT related Functions */
void appl_rcv_service_desc (UINT16 config, ATT_UUID uuid, UINT16 value_handle)
{
/* Populate Needed CCCDs here */
if (GATT_CLIENT_CONFIG == config)
{
if ( memcmp(&uuid, &AMS_RemoteCommand_UUID, ATT_128_BIT_UUID_SIZE) == 0 )
{
ams_char_info.ams_remote_command_ccc_hdl = value_handle;
}
else if ( memcmp(&uuid, &AMS_EntityUpdate_UUID, ATT_128_BIT_UUID_SIZE) == 0 )
{
ams_char_info.ams_entity_update_ccc_hdl = value_handle;
}
}
}
void appl_rcv_service_char (ATT_UUID uuid, UINT16 value_handle)
{
if ( memcmp(&uuid, &AMS_RemoteCommand_UUID, ATT_128_BIT_UUID_SIZE) == 0 )
{
ams_char_info.ams_remote_command_hdl = value_handle;
}
else if ( memcmp(&uuid, &AMS_EntityUpdate_UUID, ATT_128_BIT_UUID_SIZE) == 0 )
{
ams_char_info.ams_entity_update_hdl = value_handle;
}
else if ( memcmp(&uuid, &AMS_EntityAttribute_UUID, ATT_128_BIT_UUID_SIZE) == 0 )
{
ams_char_info.ams_entity_attribute_hdl = value_handle;
}
}
void Wait4WrtRsp(void)
{
const TickType_t xDelay = 10 / portTICK_PERIOD_MS;
UCHAR i = 0;
while ( !write_response )
{
vTaskDelay( xDelay );
if (i++ > 10 )
{
break;
}
}
write_response = 0;
}
void appl_discover_AMS(void)
{
APPL_TRC("\n<<appl discover AMS>>\n");
appl_discover_service
(
ams_service_uuid128,
ATT_128_BIT_UUID_FORMAT
);
return;
}
void AmsWrite2EnityUpdate(uint8_t entityID)
{
ATT_VALUE att_value;
uint8_t buf[5];
APPL_TRC("\n++<<AmsWrite2EnityUpdate %d>>\n", entityID);
if ( entityID == AMS_ENTITY_ID_PLAYER )
{
buf[0] = AMS_ENTITY_ID_PLAYER;
buf[1] = AMS_PLAYER_ATTRID_NAME;
buf[2] = AMS_PLAYER_ATTRID_PLAYBACKINFO;
buf[3] = AMS_PLAYER_ATTRID_VOLUME;
att_value.len = 4;
}
else if ( entityID == AMS_ENTITY_ID_QUEUE )
{
buf[0] = AMS_ENTITY_ID_QUEUE;
buf[1] = AMS_QUEUE_ATTRID_INDEX;
buf[2] = AMS_QUEUE_ATTRID_COUNT;
buf[3] = AMS_QUEUE_ATTRID_SHUFFLE;
buf[4] = AMS_QUEUE_ATTRID_REPEAT;
att_value.len = 5;
}
else if ( entityID == AMS_ENTITY_ID_TRACK )
{
buf[0] = AMS_ENTITY_ID_TRACK;
buf[1] = AMS_TRACK_ATTRID_ARTIST;
buf[2] = AMS_TRACK_ATTRID_ALBUM;
buf[3] = AMS_TRACK_ATTRID_TITLE;
buf[4] = AMS_TRACK_ATTRID_DURATION;
att_value.len = 5;
}
else
{
return;
}
att_value.val = buf;
appl_write_req (ams_char_info.ams_entity_update_hdl, &att_value);
Wait4WrtRsp();
APPL_TRC("\n--<<AmsWrite2EnityUpdate %d>>\n", entityID);
}
void AmsWrite2RemoteCommand(uint8_t cmd)
{
ATT_VALUE att_value;
uint8_t buf[1]; // retrieve the complete attribute list
buf[0] = cmd;
att_value.len = 1;
att_value.val = buf;
appl_write_req (ams_char_info.ams_remote_command_hdl, &att_value);
}
void AmsWrite2EntityAttribute(uint8_t entityID, uint8_t attrID)
{
ATT_VALUE att_value;
uint8_t buf[2]; // retrieve the complete attribute list
buf[0] = entityID;
buf[1] = attrID;
att_value.len = 2;
att_value.val = buf;
appl_write_req (ams_char_info.ams_entity_attribute_hdl, &att_value);
}
void AmsSubscribe2EnityUpdate(void)
{
ATT_VALUE att_value;
UINT16 cli_cfg;
UCHAR cfg_val[APPL_CLI_CNFG_VAL_LENGTH];
APPL_TRC("\n++<<AmsSubscribe2EnityUpdate>>\n");
cli_cfg = GATT_CLI_CNFG_NOTIFICATION;
BT_PACK_LE_2_BYTE(cfg_val, &cli_cfg);
att_value.len = APPL_CLI_CNFG_VAL_LENGTH;
att_value.val = cfg_val;
appl_write_req (ams_char_info.ams_entity_update_ccc_hdl, &att_value);
Wait4WrtRsp();
APPL_TRC("\n--<<AmsSubscribe2EnityUpdate(0x%04X)>>\n", gResult);
}
void appl_profile_operations (void)
{
const TickType_t xDelay = 100 / portTICK_PERIOD_MS;
write_response = 0;
fsm_post_event
(
APPL_FSM_ID,
ev_appl_device_init_req,
NULL
);
while ( appl_ams_state != AMS_CONNECTED )
{
vTaskDelay( xDelay );
}
appl_discover_AMS();
while ( appl_ams_state != AMS_DISCOVERED )
{
vTaskDelay( xDelay );
}
AmsSubscribe2EnityUpdate();
if (gResult == 0x0305 /* insufficient authentication */ ||
gResult == 0x030F /* insufficient Encryption */ )
{
appl_bond_with_peer();
while ( appl_ams_state != AMS_BONDED )
{
vTaskDelay( xDelay );
}
AmsSubscribe2EnityUpdate();
}
else
{
appl_ams_state = AMS_BONDED;
}
AmsWrite2EnityUpdate(AMS_ENTITY_ID_PLAYER);
AmsWrite2EnityUpdate(AMS_ENTITY_ID_QUEUE);
AmsWrite2EnityUpdate(AMS_ENTITY_ID_TRACK);
while ( appl_ams_state != AMS_DISCONNECTED )
{
vTaskDelay( xDelay );
}
}
void AmsDumpBytes (UCHAR *buffer, UINT16 length)
{
char hex_stream[49];
char char_stream[17];
UINT32 i;
UINT16 offset, count;
UCHAR c;
APPL_TRC("\n");
APPL_TRC (
"-------------------------------------------------------------------\n");
count = 0;
offset = 0;
for (i = 0; i < length; i ++ )
{
c = buffer[i];
sprintf(hex_stream + offset, "%02X ", c);
if ( (c >= 0x20) && (c <= 0x7E) )
{
char_stream[count] = c;
}
else
{
char_stream[count] = '.';
}
count ++;
offset += 3;
if ( 16 == count )
{
char_stream[count] = '\0';
count = 0;
offset = 0;
APPL_TRC ("%s %s\n",
hex_stream, char_stream);
BT_mem_set(hex_stream, 0, 49);
BT_mem_set(char_stream, 0, 17);
}
}
if ( offset != 0 )
{
char_stream[count] = '\0';
/* Maintain the alignment */
APPL_TRC ("%-48s %s\n",
hex_stream, char_stream);
}
APPL_TRC (
"-------------------------------------------------------------------\n");
APPL_TRC ("\n");
return;
}
void AmsNotificationCb(UCHAR *event_data, UINT16 event_datalen)
{
AmsDumpBytes(event_data + 2, (event_datalen - 2));
}
void AmsReadRSPCb(UCHAR *event_data, UINT16 event_datalen)
{
ATT_ATTR_HANDLE attr_handle;
BT_UNPACK_LE_2_BYTE(&attr_handle, event_data);
AmsDumpBytes(event_data + 2, (event_datalen - 2));
}
#endif /* AMS */
@@ -0,0 +1,117 @@
//*****************************************************************************
//
//! @file appl_ams.c
//!
//! @brief Application Header File for AMS.
//!
//
//*****************************************************************************
//*****************************************************************************
//
// Copyright (c) 2020, Ambiq Micro
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// 3. Neither the name of the copyright holder nor the names of its
// contributors may be used to endorse or promote products derived from this
// software without specific prior written permission.
//
// Third party software included in this distribution is subject to the
// additional license terms as defined in the /docs/licenses directory.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 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.
//
// This is part of revision 2.4.2 of the AmbiqSuite Development Package.
//
//*****************************************************************************
/**
* \file appl_ams.h
*
* Application Header File for AMS.
*/
#ifndef _H_APPL_AMS_
#define _H_APPL_AMS_
/* ----------------------------------------- Header File Inclusion */
#include "BT_api.h"
#include "BT_gatt_db_api.h"
#include "gatt_db.h"
#include "appl.h"
#include "appl_ams_att_server.h"
/* ----------------------------------------- Data Types/ Structures */
typedef struct
{
UCHAR index;
UCHAR length;
}APPL_HRS_OBS_DATA_INFO;
/* --------------------------------------------- Global Definitions */
/** LSB of error code has to be spec defined */
#define APPL_HR_CNTRL_PNT_NOT_SUPPORTED (APPL_ERR_ID | 0x80)
/* --------------------------------------------- Functions */
void appl_ams_init(void);
void appl_manage_trasnfer (GATT_DB_HANDLE handle, UINT16 config);
void appl_timer_expiry_handler (void *data, UINT16 datalen);
void appl_ams_connect(DEVICE_HANDLE * dq_handle);
void appl_send_ams_measurement (APPL_HANDLE * handle);
void appl_ams_server_reinitialize (void);
void appl_rcv_service_desc (UINT16 config, ATT_UUID uuid, UINT16 value_handle);
void appl_rcv_service_char (ATT_UUID uuid, UINT16 value_handle);
API_RESULT appl_hr_control_point_handler
(
GATT_DB_HANDLE * handle,
ATT_VALUE * value
);
API_RESULT appl_att_callback
(
ATT_HANDLE * handle,
UCHAR event_type,
API_RESULT event_result,
UCHAR * event_data,
UINT16 event_datalen
);
void ams_mtu_update(APPL_HANDLE * appl_handle, UINT16 t_mtu);
/* Profile handling */
#define APPL_PROFILE_INIT(...) appl_ams_init()
#define APPL_PROFILE_CONNECT(x) appl_ams_connect(x)
#define APPL_SEND_MEASUREMENT(x)appl_send_ams_measurement(x)
#define APPL_PROFILE_DISCONNECT_HANDLER(x) appl_ams_server_reinitialize()
#define GATT_DB_PROFILE_HANDLER gatt_db_ams_handler
#define APPL_PROFILE_HVN_NTF_COMPLETE_HANDLER(x, y, z)
#define APPL_PROFILE_HVN_IND_COMPLETE_HANDLER(x, y, z)
#define APPL_PROFILE_MTU_UPDT_COMPLETE_HANDLER(x, y) ams_mtu_update(x, y)
#define APPL_USE_IDLE_TIMER
#define APPL_IDLE_TIMEOUT 30
#endif /* _H_APPL_AMS_ */
@@ -0,0 +1,158 @@
//*****************************************************************************
//
//! @file appl_ams_att_server.h
//!
//! @brief ATT Server Application Header File
//!
//
//*****************************************************************************
//*****************************************************************************
//
// Copyright (c) 2020, Ambiq Micro
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// 3. Neither the name of the copyright holder nor the names of its
// contributors may be used to endorse or promote products derived from this
// software without specific prior written permission.
//
// Third party software included in this distribution is subject to the
// additional license terms as defined in the /docs/licenses directory.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 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.
//
// This is part of revision 2.4.2 of the AmbiqSuite Development Package.
//
//*****************************************************************************
/**
* \file appl_ams_att_server.h
*
* ATT Server Application Header File
*/
/*
* Copyright (C) 2013. Mindtree Ltd.
* All rights reserved.
*/
#ifndef _H_APPL_AMS_ATT_SERVER_
#define _H_APPL_AMS_ATT_SERVER_
/* ----------------------------------------- Header File Inclusion */
#include "BT_api.h"
#include "BT_gatt_db_api.h"
#define APPL_ATT_WRITE_QUEUE_SIZE 10
#define APPL_ATT_MAX_WRITE_BUFFER_SIZE 256 /* 255 */
#define APPL_ATT_MTU ATT_MAX_MTU
#define APPL_SERVER_BUFFER_SIZE 256 /* 256 */
#define APPL_MAX_GROUP_TYPE_QUERIED 5
#define APPL_MAX_HNDL_UUID_LIST_SIZE 5
#define APPL_MAX_HNDL_LIST_SIZE 11
#define APPL_MAX_HNDL_VALUE_SIZE 5
/* ATT PDU Request Length */
#define APPL_ATT_XCNHG_MTU_REQ_LEN 2
#define APPL_ATT_XCNHG_MTU_RSP_LEN 2
#define APPL_ATT_FIND_INFO_REQ_LEN 4
#define APPL_ATT_FIND_INFO_RSP_LEN_1 5
#define APPL_ATT_FIND_INFO_RSP_LEN_2 22
#define ATT_FIND_BY_TYPE_VAL_RSP_LEN1 4
#define ATT_FIND_BY_TYPE_VAL_RSP_LEN2 21
#define APPL_ATT_READ_BY_TYPE_REQ_LEN_1 6
#define APPL_ATT_READ_BY_TYPE_REQ_LEN_2 20
#define ATT_READ_BY_TYPE_RSP_LEN_1 3
#define ATT_READ_BY_TYPE_RSP_LEN_2 22
#define APPL_ATT_READ_REQ_LEN 2
#define APPL_ATT_READ_RSP_LEN_1 0
#define APPL_ATT_READ_RSP_LEN_2 22
#define APPL_ATT_READ_BLOB_REQ_LEN 4
#define APPL_ATT_READ_BLOB_RSP_LEN_1 0
#define APPL_ATT_READ_BLOB_RSP_LEN_2 22
#define APPL_ATT_READ_BY_GROUP_REQ_LEN_1 6
#define APPL_ATT_READ_BY_GROUP_REQ_LEN_2 20
#define APPL_ATT_READ_BY_GROUP_RSP_LEN_1 5
#define APPL_ATT_READ_BY_GROUP_RSP_LEN_2 22
#define APPL_ATT_EXECUTE_WRITE_REQ_LEN 1
#define APPL_ATT_INVALID_LEN 0xFF
#define APPL_MAX_VALID_ATT_PDU_LEN_CHK 7
/** Application Defined error */
#define APPL_ATT_INVALID_OFFSET 0xFFFF
#define ATT_INVALID_ATTR_HANDLE_VAL 0x0000
#define APPL_MAX_MULTIPLE_READ_COUNT 11
#define APPL_CHECK_IF_ATT_REQUEST(type)\
((((((type) > 0x13) && ((type) < 0x16)) ||\
(((type) > 0x1E) && (((type) != ATT_SIGNED_WRITE_CMD) &&\
((type) != ATT_WRITE_CMD)))) || (0x01 == ((type) & 0x01)))? BT_FALSE : BT_TRUE)
#define APPL_ATT_PREPARE_QUEUE_INIT(i)\
appl_att_write_queue[(i)].handle_value.handle = 0;\
appl_att_write_queue[(i)].offset = 0xFFFF;\
appl_att_write_queue[(i)].handle_value.value.len = 0;\
appl_att_write_queue[(i)].handle_value.value.val = NULL;
API_RESULT appl_discover_service
(
/* IN */ ATT_UUID uuid,
/* IN */ UCHAR uuid_frmt
);
API_RESULT appl_write_req
(
/* IN */ ATT_ATTR_HANDLE handle,
/* IN */ ATT_VALUE * value
);
API_RESULT appl_read_req
(
/* IN */ ATT_ATTR_HANDLE handle
);
API_RESULT appl_att_server_init(void);
API_RESULT appl_handle_unsupported_op_code (ATT_HANDLE *handle, UCHAR op_code);
API_RESULT appl_validate_att_pdu_req_len
(
UCHAR att_event,
UINT16 event_datalen
);
#ifdef SMP_DATA_SIGNING
void appl_gatt_signing_complete (API_RESULT status, UCHAR * data, UINT16 datalen);
void appl_gatt_signing_verification_complete
(
API_RESULT status,
UCHAR * data,
UINT16 datalen
);
#endif /* SMP_DATA_SIGNING */
#endif /* _H_APPL_AMS_ATT_SERVER_ */
@@ -0,0 +1,227 @@
//*****************************************************************************
//
//! @file appl_gap_config_params.c
//!
//! @brief This file contains GAP Configuration Parameters used by the application.
//!
//
//*****************************************************************************
//*****************************************************************************
//
// Copyright (c) 2020, Ambiq Micro
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// 3. Neither the name of the copyright holder nor the names of its
// contributors may be used to endorse or promote products derived from this
// software without specific prior written permission.
//
// Third party software included in this distribution is subject to the
// additional license terms as defined in the /docs/licenses directory.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 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.
//
// This is part of revision 2.4.2 of the AmbiqSuite Development Package.
//
//*****************************************************************************
/**
* \file appl_gap_config_params.c
*
* This file contains GAP Configuration Parameters used by the application.
*/
/* --------------------------------------------- Header File Inclusion */
#include "appl_gap.h"
#ifdef AMS
/* --------------------------------------------- External Global Variables */
/* --------------------------------------------- Exported Global Variables */
/* --------------------------------------------- Static Global Variables */
#if ((defined APPL_GAP_BROADCASTER_SUPPORT) || (defined APPL_GAP_PERIPHERAL_SUPPORT))
/** Advertisement Data Options */
const APPL_GAP_ADV_DATA appl_gap_adv_data[APPL_GAP_MAX_ADV_DATA_OPTIONS] =
{
/* GAP Advertisement Parameters */
{
{
/**
* Flags:
* 0x01: LE Limited Discoverable Mode
* 0x02: LE General Discoverable Mode
* 0x04: BR/EDR Not Supported
* 0x08: Simultaneous LE and BR/EDR to Same Device
* Capable (Controller)
* 0x10: Simultaneous LE and BR/EDR to Same Device
* Capable (Host)
*/
0x02, 0x01,
(BT_AD_FLAGS_LE_GENERAL_DISC_MODE | BT_AD_FLAGS_LE_BR_EDR_SUPPORT),
/**
* Service UUID List:
* Battery Service (0x180F)
* DeviceInformation Service (0x180A)
*/
0x05, 0x03, 0x0F, 0x18, 0x0A, 0x18,
/**
* Shortened Device Name: AM
*/
0x03, 0x08, 0x41, 0x4d,
/**
* List of 16-bit Service Solicitation UUIDs(AMS UUID)
*/
0x11, 0x15, 0xDC, 0xF8, 0x55, 0xAD, 0x02, 0xC5, 0xF4, 0x8E, 0x3A, 0x43, 0x36, 0x0F, 0x2B, 0x50, 0xD3, 0x89
},
31
}
};
/* Advertisement parameters options */
const APPL_GAP_ADV_PARAM appl_gap_adv_param[APPL_GAP_MAX_ADV_PARAM_OPTIONS] =
{
/* 0 - Normal Advertising Params */
{
32,
32,
7,
0
},
/* 1 - Fast Connection Advertising Params */
{
32,
48,
7,
0
},
/* 2 - Low Power Advertising Params */
{
1600,
4000,
7,
0
}
};
/* Advertisement Table */
APPL_GAP_ADV_INFO appl_gap_adv_table =
{
appl_gap_adv_data,
appl_gap_adv_param,
APPL_GAP_ADV_IDLE
};
#endif /* APPL_GAP_BROADCASTER || APPL_GAP_PERIPHERAL_SUPPORT */
#if ((defined APPL_GAP_OBSERVER_SUPPORT) || (defined APPL_GAP_CENTRAL_SUPPORT))
/* Scan Parameters Option */
const APPL_GAP_SCAN_PARAM appl_gap_scan_param[APPL_GAP_MAX_SCAN_PARAM_OPTIONS] =
{
/* Normal Scan Params */
{
32,
7,
0
},
/* Fast Connection Scan Params */
{
48,
7,
0
},
/* Low Power Scan Params */
{
4000,
7,
0
}
};
/* Scan Table */
APPL_GAP_SCAN_INFO appl_gap_scan_table =
{
appl_gap_scan_param,
APPL_GAP_SCAN_IDLE
};
#endif /* APPL_GAP_OBSERVER_SUPPORT || APPL_GAP_CENTRAL_SUPPORT */
#ifdef APPL_GAP_CENTRAL_SUPPORT
/* Connection Parameters Options */
const APPL_GAP_CONN_PARAM appl_gap_conn_param[APPL_GAP_MAX_CONN_PARAM_OPTIONS] =
{
{
4,
4,
0,
40,
56,
0,
955,
32,
32
}
};
/* GAP Connection Table */
APPL_GAP_CONN_INFO appl_gap_conn_table =
{
appl_gap_conn_param,
APPL_GAP_CONN_IDLE
};
#endif /* APPL_GAP_CENTRAL_SUPPORT */
#endif /* AMS */
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,157 @@
//*****************************************************************************
//
//! @file gatt_db.h
//!
//! @brief GATT Databse.
//!
//
//*****************************************************************************
//*****************************************************************************
//
// Copyright (c) 2020, Ambiq Micro
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// 3. Neither the name of the copyright holder nor the names of its
// contributors may be used to endorse or promote products derived from this
// software without specific prior written permission.
//
// Third party software included in this distribution is subject to the
// additional license terms as defined in the /docs/licenses directory.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 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.
//
// This is part of revision 2.4.2 of the AmbiqSuite Development Package.
//
//*****************************************************************************
/**
* \file gatt_db.h
*/
/*
* Copyright (C) 2013. Mindtree Ltd.
* All rights reserved.
*/
#ifndef _H_GATT_DB_
#define _H_GATT_DB_
/**
* addgroup gatt_db_module
*/
/**
* defgroup gatt_db_tuneable_param Tuneable Parameters
* {
* This section defines the Tuneable Constants of Data Base Module.
*/
/** Number of Characteristics in the data base */
#define GATT_CHARACTERISTIC_COUNT 13
/** Number of Services in the data base */
#define GATT_SERVICE_COUNT 4
/** Number of Characteristics that are configurable by the client */
#define GATT_DB_MAX_CONFIGUREABLE_CHAR 3
/** Maximum Length of any Characteristic Value/Descriptor */
#define GATT_DB_MAX_VAL_LENGTH 32
#define GATT_VALUE_ARRAY_SIZE 1
#define GATT_CONST_VALUE_ARRAY_SIZE 180
#define GATT_DB_PEER_VALUE_ARRAY_SIZE 4
#define GATT_DB_MAX_ATTRIBUTES 34
#define GATT_UUID_ARRAY_SIZE 54
#define GATT_DB_MAX_TYPE_COUNT 21
#define GATT_DB_MAX_PEER_CONFIGURATION \
(GATT_DB_PEER_VALUE_ARRAY_SIZE * BT_MAX_DEVICE_QUEUE_SIZE)
/** \} */
/** Service Instance Reference */
/** GAP Service */
#define GATT_SER_GAP_INST 0
/** GATT Service */
#define GATT_SER_GATT_INST 1
/** Battery Service */
#define GATT_SER_BATTERY_INST 2
/** DeviceInformation Service */
#define GATT_SER_DEV_INFO_INST 3
/** Characteristic Instance Reference */
/** DeviceName */
#define GATT_CHAR_DEV_NAME_INST 0
/** Appearance */
#define GATT_CHAR_APPEARANCE_INST 1
/** Service Changed */
#define GATT_CHAR_SER_CHNGD_INST 2
/** BatteryLevel */
#define GATT_CHAR_BATTERY_LVL_INST 3
/** ManufacturerName */
#define GATT_CHAR_MAN_NAME_INST 4
/** ModelNumber */
#define GATT_CHAR_MODEL_NO_INST 5
/** SerialNumber */
#define GATT_CHAR_SL_NO_INST 6
/** FirmwareRevision */
#define GATT_CHAR_FW_REV_INST 7
/** HardwareRevision */
#define GATT_CHAR_HW_REV_INST 8
/** SoftwareRevision */
#define GATT_CHAR_SW_REV_INST 9
/** SystemId */
#define GATT_CHAR_SYS_ID_INST 10
/** RegCertDataList */
#define GATT_CHAR_REG_CERT_DATA_INST 11
/** PnPID */
#define GATT_CHAR_PNP_ID_INST 12
#endif /* _H_GATT_DB_ */
@@ -0,0 +1,666 @@
//*****************************************************************************
//
//! @file appl_ancs.c
//!
//! @brief ANCS service.
//!
//
//*****************************************************************************
//*****************************************************************************
//
// Copyright (c) 2020, Ambiq Micro
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// 3. Neither the name of the copyright holder nor the names of its
// contributors may be used to endorse or promote products derived from this
// software without specific prior written permission.
//
// Third party software included in this distribution is subject to the
// additional license terms as defined in the /docs/licenses directory.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 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.
//
// This is part of revision 2.4.2 of the AmbiqSuite Development Package.
//
//*****************************************************************************
/**
* \file appl_ancs.c
*
*/
/* --------------------------------------------- Header File Inclusion */
#ifdef ANCS
#include "appl.h"
#include "BT_common.h"
#include "BT_hci_api.h"
#include "BT_att_api.h"
#include "BT_smp_api.h"
#include "smp_pl.h"
#include "l2cap.h"
#include "fsm_defines.h"
#include "task.h"
#include "queue.h"
/* ----------------------------------------- Configuration Defines */
extern uint32_t am_util_stdio_printf(const char *pcFmt, ...);
#undef APPL_TRC
#undef APPL_ERR
#define APPL_TRC am_util_stdio_printf
#define APPL_ERR am_util_stdio_printf
/* ----------------------------------------- Macro Defines */
/**@brief Category IDs for iOS notifications. */
typedef enum
{
BLE_ANCS_CATEGORY_ID_OTHER, /**< The iOS notification belongs to the "other" category. */
BLE_ANCS_CATEGORY_ID_INCOMING_CALL, /**< The iOS notification belongs to the "Incoming Call" category. */
BLE_ANCS_CATEGORY_ID_MISSED_CALL, /**< The iOS notification belongs to the "Missed Call" category. */
BLE_ANCS_CATEGORY_ID_VOICE_MAIL, /**< The iOS notification belongs to the "Voice Mail" category. */
BLE_ANCS_CATEGORY_ID_SOCIAL, /**< The iOS notification belongs to the "Social" category. */
BLE_ANCS_CATEGORY_ID_SCHEDULE, /**< The iOS notification belongs to the "Schedule" category. */
BLE_ANCS_CATEGORY_ID_EMAIL, /**< The iOS notification belongs to the "E-mail" category. */
BLE_ANCS_CATEGORY_ID_NEWS, /**< The iOS notification belongs to the "News" category. */
BLE_ANCS_CATEGORY_ID_HEALTH_AND_FITNESS, /**< The iOS notification belongs to the "Health and Fitness" category. */
BLE_ANCS_CATEGORY_ID_BUSINESS_AND_FINANCE, /**< The iOS notification belongs to the "Buisness and Finance" category. */
BLE_ANCS_CATEGORY_ID_LOCATION, /**< The iOS notification belongs to the "Location" category. */
BLE_ANCS_CATEGORY_ID_ENTERTAINMENT /**< The iOS notification belongs to the "Entertainment" category. */
} ancc_category_id_values_t;
/**@brief Event IDs for iOS notifications. */
typedef enum
{
BLE_ANCS_EVENT_ID_NOTIFICATION_ADDED, /**< The iOS notification was added. */
BLE_ANCS_EVENT_ID_NOTIFICATION_MODIFIED, /**< The iOS notification was modified. */
BLE_ANCS_EVENT_ID_NOTIFICATION_REMOVED /**< The iOS notification was removed. */
} ancc_evt_id_values_t;
/**@brief Control point command IDs that the Notification Consumer can send to the Notification Provider. */
typedef enum
{
BLE_ANCS_COMMAND_ID_GET_NOTIF_ATTRIBUTES, /**< Requests attributes to be sent from the NP to the NC for a given notification. */
BLE_ANCS_COMMAND_ID_GET_APP_ATTRIBUTES, /**< Requests attributes to be sent from the NP to the NC for a given iOS App. */
BLE_ANCS_COMMAND_ID_GET_PERFORM_NOTIF_ACTION, /**< Requests an action to be performed on a given notification, for example dismiss an alarm. */
} ancc_command_id_values_t;
/**@brief IDs for iOS notification attributes. */
typedef enum
{
BLE_ANCS_NOTIF_ATTR_ID_APP_IDENTIFIER, /**< Identifies that the attribute data is of an "App Identifier" type. */
BLE_ANCS_NOTIF_ATTR_ID_TITLE, /**< Identifies that the attribute data is a "Title". Needs to be followed by a 2-bytes max length parameter*/
BLE_ANCS_NOTIF_ATTR_ID_SUBTITLE, /**< Identifies that the attribute data is a "Subtitle". Needs to be followed by a 2-bytes max length parameter*/
BLE_ANCS_NOTIF_ATTR_ID_MESSAGE, /**< Identifies that the attribute data is a "Message". Needs to be followed by a 2-bytes max length parameter*/
BLE_ANCS_NOTIF_ATTR_ID_MESSAGE_SIZE, /**< Identifies that the attribute data is a "Message Size". */
BLE_ANCS_NOTIF_ATTR_ID_DATE, /**< Identifies that the attribute data is a "Date". */
BLE_ANCS_NOTIF_ATTR_ID_POSITIVE_ACTION_LABEL, /**< The notification has a "Positive action" that can be executed associated with it. */
BLE_ANCS_NOTIF_ATTR_ID_NEGATIVE_ACTION_LABEL, /**< The notification has a "Negative action" that can be executed associated with it. */
} ancc_notif_attr_id_values_t;
/**@brief Typedef for iOS notifications. */
typedef struct
{
uint8_t event_id; /**< This field informs the accessory whether the given iOS notification was added, modified, or removed. The enumerated values for this field are defined in EventID Values.. */
uint8_t event_flags; /**< A bitmask whose set bits inform an NC of specificities with the iOS notification. */
uint8_t category_id; /**< A numerical value providing a category in which the iOS notification can be classified. */
uint8_t category_count; /**< The current number of active iOS notifications in the given category. */
uint32_t notification_uid; /**< A 32-bit numerical value that is the unique identifier (UID) for the iOS notification. */
} ancc_notif_t;
typedef enum
{
ANCS_DISCONNECTED,
ANCS_CONNECTED,
ANCS_BONDED,
ANCS_DISCOVERED,
} ancs_appl_state_t;
/* ----------------------------------------- External Global Variables */
void appl_profile_operations (void);
void AncsGetNotificationAttribute(uint32_t notiUid);
extern BT_DEVICE_ADDR g_bd_addr;
/* ----------------------------------------- Exported Global Variables */
QueueHandle_t xNtfUIDQueue;
/* ----------------------------------------- Static Global Variables */
DECL_STATIC UCHAR write_response = 0;
DECL_STATIC API_RESULT gResult = 0;
DECL_STATIC ancs_appl_state_t appl_ancs_state = ANCS_DISCONNECTED;
DECL_STATIC ATT_UUID ancs_service_uuid128 = {.uuid_128.value = {0xD0, 0x00, 0x2D, 0x12, 0x1E, 0x4B, 0x0F, 0xA4, 0x99, 0x4E, 0xCE, 0xB5, 0x31, 0xF4, 0x05, 0x79}};
DECL_STATIC ATT_UUID ANCS_ControlPoint_UUID = {.uuid_128.value = {0xD9, 0xD9, 0xAA, 0xFD, 0xBD, 0x9B, 0x21, 0x98, 0xA8, 0x49, 0xE1, 0x45, 0xF3, 0xD8, 0xD1, 0x69}};
DECL_STATIC ATT_UUID ANCS_NotificationSource_UUID = {.uuid_128.value = {0xBD, 0x1D, 0xA2, 0x99, 0xE6, 0x25, 0x58, 0x8C, 0xD9, 0x42, 0x01, 0x63, 0x0D, 0x12, 0xBF, 0x9F}};
DECL_STATIC ATT_UUID ANCS_DataSource_UUID = {.uuid_128.value = {0xFB, 0x7B, 0x7C, 0xCE, 0x6A, 0xB3, 0x44, 0xBE, 0xB5, 0x4B, 0xD6, 0x24, 0xE9, 0xC6, 0xEA, 0x22}};
/* BLE Connection Handle */
//DECL_STATIC UINT16 appl_ble_connection_handle;
/** ANCS Characteristic related information */
typedef struct
{
/* ANCS Service */
/* Notification Source */
ATT_ATTR_HANDLE ancs_notification_source_hdl;
/* Notification Source - CCC */
ATT_ATTR_HANDLE ancs_notification_source_ccc_hdl;
/* Control Point */
ATT_ATTR_HANDLE ancs_control_point_hdl;
/* Data Source */
ATT_ATTR_HANDLE ancs_data_source_hdl;
/* Data Source - CCC */
ATT_ATTR_HANDLE ancs_data_source_ccc_hdl;
} ANCS_CHAR_INFO;
#define APPL_CLI_CNFG_VAL_LENGTH 2
DECL_STATIC ANCS_CHAR_INFO ancs_char_info;
#ifdef APPL_MENU_OPS
BT_DEVICE_ADDR g_peer_bd_addr;
static UCHAR ancs_client_menu[] =
"\n\
\r\n\
1. Bond with peer \r\n\
\r\n\
2. Discover ANCS \r\n\
\r\n\
3. Set Data Source CCCD \r\n\
\r\n\
4. Set Notification Source CCCD \r\n\
\r\n\
5. Get Notification Attribute by UID \r\n\
\r\n\
Your Option? \0";
#endif /* APPL_MENU_OPS */
/* --------------------------------------------- Constants */
/* --------------------------------------------- Static Global Variables */
/* --------------------------------------------- Functions */
void appl_bond_with_peer(void)
{
API_RESULT retval;
/* If connection is successful, initiate bonding [Step 2(c)] */
SMP_AUTH_INFO auth;
SMP_BD_ADDR smp_peer_bd_addr;
SMP_BD_HANDLE smp_bd_handle;
APPL_TRC("\n<<appl_bond_with_peer>>\n");
auth.param = 1;
auth.bonding = 1;
auth.ekey_size = 12;
auth.security = SMP_SEC_LEVEL_1;
BT_COPY_BD_ADDR(smp_peer_bd_addr.addr, g_bd_addr.addr);
BT_COPY_TYPE(smp_peer_bd_addr.type, g_bd_addr.type);
retval = BT_smp_get_bd_handle
(
&smp_peer_bd_addr,
&smp_bd_handle
);
if (API_SUCCESS == retval)
{
retval = BT_smp_authenticate (&smp_bd_handle, &auth);
}
if (API_SUCCESS != retval)
{
APPL_TRC (
"Initiation of Authentication Failed. Reason 0x%04X\n",
retval);
}
/**
* Application will receive authentication complete event,
* in SMP Callback.
*
* Look for 'SMP_AUTHENTICATION_COMPLETE' event handling in
* 'appl_smp_callback'.
*/
}
void appl_ancs_init(void)
{
appl_ancs_state = ANCS_DISCONNECTED;
APPL_TRC("\n\n<<appl_ancs_init>>\n\n");
}
void appl_ancs_connect(APPL_HANDLE * appl_handle)
{
APPL_STATE_T state = GET_APPL_STATE(*appl_handle);
if ( state == SL_0_TRANSPORT_OPERATING && appl_ancs_state == ANCS_DISCONNECTED )
{
appl_ancs_state = ANCS_CONNECTED;
APPL_TRC("\n\n<<CONNECTED>>\n\n");
}
else if ( state == SL_0_TRANSPORT_OPERATING && appl_ancs_state == ANCS_DISCOVERED )
{
appl_ancs_state = ANCS_BONDED;
APPL_TRC("\n\n<<BONDED>>\n\n");
}
else
{
appl_ancs_state = ANCS_DISCONNECTED;
APPL_TRC("\n\n<<DISCONNECTED>>\n\n");
}
}
void appl_search_complete(void)
{
appl_ancs_state = ANCS_DISCOVERED;
APPL_TRC("\n\n<<DISCOVERED>>\n\n");
}
void appl_recvice_att_event(UCHAR att_event, API_RESULT event_result)
{
if ( att_event == ATT_WRITE_RSP )
{
write_response = 1;
gResult = 0;
}
else if ( att_event == ATT_ERROR_RSP )
{
gResult = event_result;
}
}
void appl_manage_trasnfer (GATT_DB_HANDLE handle, UINT16 config)
{
APPL_TRC("\n\n<<appl_manage_trasnfer>>\n\n");
}
void appl_send_ancs_measurement (APPL_HANDLE * handle)
{
APPL_TRC("\n\n<<appl_send_ancs_measurement>>\n\n");
}
void appl_timer_expiry_handler (void *data, UINT16 datalen)
{
APPL_TRC("\n\n<<appl_timer_expiry_handler>>\n\n");
}
void appl_ancs_server_reinitialize (void)
{
appl_ancs_state = ANCS_DISCONNECTED;
APPL_TRC("\n\n<<appl_ancs_server_reinitialize>>\n\n");
}
void ancs_mtu_update(APPL_HANDLE * appl_handle, UINT16 t_mtu)
{
UINT16 mtu = 0;
BT_att_access_mtu(&APPL_GET_ATT_INSTANCE(*appl_handle),
&mtu);
APPL_TRC("appl_handle 0x%x t_mtu = %d %d\n", *appl_handle, t_mtu, mtu);
}
/* ------------------------------- ATT related Functions */
void appl_rcv_service_desc (UINT16 config, ATT_UUID uuid, UINT16 value_handle)
{
/* Populate Needed CCCDs here */
if (GATT_CLIENT_CONFIG == config)
{
if ( memcmp(&uuid, &ANCS_NotificationSource_UUID, ATT_128_BIT_UUID_SIZE) == 0 )
{
ancs_char_info.ancs_notification_source_ccc_hdl = value_handle;
}
else if ( memcmp(&uuid, &ANCS_DataSource_UUID, ATT_128_BIT_UUID_SIZE) == 0 )
{
ancs_char_info.ancs_data_source_ccc_hdl = value_handle;
}
}
}
void appl_rcv_service_char (ATT_UUID uuid, UINT16 value_handle)
{
if ( memcmp(&uuid, &ANCS_NotificationSource_UUID, ATT_128_BIT_UUID_SIZE) == 0 )
{
ancs_char_info.ancs_notification_source_hdl = value_handle;
}
else if ( memcmp(&uuid, &ANCS_ControlPoint_UUID, ATT_128_BIT_UUID_SIZE) == 0 )
{
ancs_char_info.ancs_control_point_hdl = value_handle;
}
else if ( memcmp(&uuid, &ANCS_DataSource_UUID, ATT_128_BIT_UUID_SIZE) == 0 )
{
ancs_char_info.ancs_data_source_hdl = value_handle;
}
}
void Wait4WrtRsp(void)
{
const TickType_t xDelay = 10 / portTICK_PERIOD_MS;
UCHAR i = 0;
while ( !write_response )
{
vTaskDelay( xDelay );
if (i++ > 10 )
{
break;
}
}
write_response = 0;
}
void appl_discover_ANCS(void)
{
APPL_TRC("\n<<appl_discover_ANCS>>\n");
appl_discover_service
(
ancs_service_uuid128,
ATT_128_BIT_UUID_FORMAT
);
return;
}
void AncsSubscribeNotifications(void)
{
ATT_VALUE att_value;
UINT16 cli_cfg;
UCHAR cfg_val[APPL_CLI_CNFG_VAL_LENGTH];
APPL_TRC("\n++<<AncsSubscribeNotifications>>\n");
cli_cfg = GATT_CLI_CNFG_NOTIFICATION;
BT_PACK_LE_2_BYTE(cfg_val, &cli_cfg);
att_value.len = APPL_CLI_CNFG_VAL_LENGTH;
att_value.val = cfg_val;
appl_write_req(ancs_char_info.ancs_data_source_ccc_hdl, &att_value);
Wait4WrtRsp();
cli_cfg = GATT_CLI_CNFG_NOTIFICATION;
BT_PACK_LE_2_BYTE(cfg_val, &cli_cfg);
att_value.len = APPL_CLI_CNFG_VAL_LENGTH;
att_value.val = cfg_val;
appl_write_req(ancs_char_info.ancs_notification_source_ccc_hdl, &att_value);
Wait4WrtRsp();
APPL_TRC("\n--<<AncsSubscribeNotifications(0x%04X)>>\n", gResult);
}
void appl_profile_operations (void)
{
const TickType_t xDelay = 100 / portTICK_PERIOD_MS;
UINT32 NtfUID;
write_response = 0;
xNtfUIDQueue = 0;
xNtfUIDQueue = xQueueCreate( 10, sizeof(UINT32) );
fsm_post_event
(
APPL_FSM_ID,
ev_appl_device_init_req,
NULL
);
while ( appl_ancs_state != ANCS_CONNECTED)
{
vTaskDelay( xDelay );
}
appl_discover_ANCS();
while ( appl_ancs_state != ANCS_DISCOVERED )
{
vTaskDelay( xDelay );
}
AncsSubscribeNotifications();
if ( gResult == 0x0305 /* insufficient authentication */ ||
gResult == 0x030F /* insufficient Encryption */ )
{
appl_bond_with_peer();
while ( appl_ancs_state != ANCS_BONDED )
{
vTaskDelay( xDelay );
}
AncsSubscribeNotifications();
}
else
{
appl_ancs_state = ANCS_BONDED;
}
while ( appl_ancs_state != ANCS_DISCONNECTED )
{
if ( xQueueReceive( xNtfUIDQueue, &( NtfUID ), ( TickType_t ) 10 ) )
{
AncsGetNotificationAttribute(NtfUID);
}
}
if ( xNtfUIDQueue != 0 )
{
vQueueDelete( xNtfUIDQueue);
}
}
void AncsDumpBytes (UCHAR *buffer, UINT16 length)
{
char hex_stream[49];
char char_stream[17];
UINT32 i;
UINT16 offset, count;
UCHAR c;
APPL_TRC (
"-------------------------------------------------------------------\n");
count = 0;
offset = 0;
for ( i = 0; i < length; i++ )
{
c = buffer[i];
sprintf(hex_stream + offset, "%02X ", c);
if ( (c >= 0x20) && (c <= 0x7E) )
{
char_stream[count] = c;
}
else
{
char_stream[count] = '.';
}
count ++;
offset += 3;
if ( 16 == count )
{
char_stream[count] = '\0';
count = 0;
offset = 0;
APPL_TRC ("%s %s\n",
hex_stream, char_stream);
BT_mem_set(hex_stream, 0, 49);
BT_mem_set(char_stream, 0, 17);
}
}
if ( offset != 0 )
{
char_stream[count] = '\0';
/* Maintain the alignment */
APPL_TRC ("%-48s %s\n",
hex_stream, char_stream);
}
APPL_TRC (
"-------------------------------------------------------------------\n\n");
return;
}
void AncsGetNotificationAttribute(uint32_t notiUid)
{
API_RESULT retval;
ATT_VALUE att_value;
// An example to get notification attributes
uint16_t max_len = 256;
uint8_t buf[19]; // retrieve the complete attribute list
APPL_TRC("++<<GetNtfUID:%X>>\n", notiUid);
buf[0] = BLE_ANCS_COMMAND_ID_GET_NOTIF_ATTRIBUTES; // put command
uint8_t *p = &buf[1];
BT_UNPACK_LE_4_BYTE(p, (uint8_t*)(&notiUid)); // encode notification uid
// encode attribute IDs
buf[5] = BLE_ANCS_NOTIF_ATTR_ID_APP_IDENTIFIER;
buf[6] = BLE_ANCS_NOTIF_ATTR_ID_TITLE;
// 2 byte length
buf[7] = max_len;
buf[8] = max_len >> 8;
buf[9] = BLE_ANCS_NOTIF_ATTR_ID_SUBTITLE;
buf[10] = max_len;
buf[11] = max_len >> 8;
buf[12] = BLE_ANCS_NOTIF_ATTR_ID_MESSAGE;
buf[13] = max_len;
buf[14] = max_len >> 8;
buf[15] = BLE_ANCS_NOTIF_ATTR_ID_MESSAGE_SIZE;
buf[16] = BLE_ANCS_NOTIF_ATTR_ID_DATE;
buf[17] = BLE_ANCS_NOTIF_ATTR_ID_POSITIVE_ACTION_LABEL;
buf[18] = BLE_ANCS_NOTIF_ATTR_ID_NEGATIVE_ACTION_LABEL;
att_value.len = 19;
att_value.val = buf;
retval = appl_write_req(ancs_char_info.ancs_control_point_hdl, &att_value);
//APPL_TRC ("retval 0x%04X\n", retval);
if ( retval == API_SUCCESS )
{
Wait4WrtRsp();
}
APPL_TRC("--<<GetNtfUID:%X>>\n", notiUid);
}
void AncsNotificationCb(UCHAR *event_data, UINT16 event_datalen)
{
ATT_ATTR_HANDLE attr_handle;
ancc_notif_t *NotificationSource;
BT_UNPACK_LE_2_BYTE(&attr_handle, event_data);
if ( attr_handle == ancs_char_info.ancs_notification_source_hdl )
{
NotificationSource = (ancc_notif_t *)(event_data + 2);
switch(NotificationSource->category_id)
{
case(BLE_ANCS_CATEGORY_ID_OTHER):
APPL_TRC("OTHER(%X)\n", NotificationSource->notification_uid);
break;
case(BLE_ANCS_CATEGORY_ID_INCOMING_CALL):
APPL_TRC("INCOMING_CALL(%X)\n", NotificationSource->notification_uid);
break;
case(BLE_ANCS_CATEGORY_ID_MISSED_CALL):
APPL_TRC("MISSED_CALL(%X)\n", NotificationSource->notification_uid);
break;
case(BLE_ANCS_CATEGORY_ID_VOICE_MAIL):
APPL_TRC("VOICE_MAIL(%X)\n", NotificationSource->notification_uid);
break;
case(BLE_ANCS_CATEGORY_ID_SOCIAL):
APPL_TRC("SOCIAL(%X)\n", NotificationSource->notification_uid);
break;
case(BLE_ANCS_CATEGORY_ID_SCHEDULE):
APPL_TRC("SCHEDULE(%X)\n", NotificationSource->notification_uid);
break;
case(BLE_ANCS_CATEGORY_ID_EMAIL):
APPL_TRC("EMAIL(%X)\n", NotificationSource->notification_uid);
break;
case(BLE_ANCS_CATEGORY_ID_NEWS):
APPL_TRC("NEWS(%X)\n", NotificationSource->notification_uid);
break;
case(BLE_ANCS_CATEGORY_ID_HEALTH_AND_FITNESS):
APPL_TRC("HEALTH_AND_FITNESS(%X)\n", NotificationSource->notification_uid);
break;
case(BLE_ANCS_CATEGORY_ID_BUSINESS_AND_FINANCE):
APPL_TRC("BUSINESS_AND_FINANCE(%X)\n", NotificationSource->notification_uid);
break;
case(BLE_ANCS_CATEGORY_ID_LOCATION):
APPL_TRC("LOCATION(%X)\n", NotificationSource->notification_uid);
break;
case(BLE_ANCS_CATEGORY_ID_ENTERTAINMENT):
APPL_TRC("ENTERTAINMENT(%X)\n", NotificationSource->notification_uid);
break;
default:
break;
}
//APPL_TRC("Spaces %d\n", uxQueueSpacesAvailable(xNtfUIDQueue));
xQueueSend( xNtfUIDQueue, ( void * ) &(NotificationSource->notification_uid), ( TickType_t ) 0 );
}
#if 0
else if ( attr_handle == ancs_char_info.ancs_data_source_hdl )
{
APPL_TRC("data source\n");
}
#endif
AncsDumpBytes(event_data + 2, (event_datalen-2));
}
#endif /* ANCS */
@@ -0,0 +1,122 @@
//*****************************************************************************
//
//! @file appl_ancs.h
//!
//! @brief Application Header File for ANCS.
//!
//
//*****************************************************************************
//*****************************************************************************
//
// Copyright (c) 2020, Ambiq Micro
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// 3. Neither the name of the copyright holder nor the names of its
// contributors may be used to endorse or promote products derived from this
// software without specific prior written permission.
//
// Third party software included in this distribution is subject to the
// additional license terms as defined in the /docs/licenses directory.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 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.
//
// This is part of revision 2.4.2 of the AmbiqSuite Development Package.
//
//*****************************************************************************
/**
* \file appl_ancs.h
*
* Application Header File for ANCS.
*/
/*
* Copyright (C) 2013. Mindtree Ltd.
* All rights reserved.
*/
#ifndef _H_APPL_ANCS_
#define _H_APPL_ANCS_
/* ----------------------------------------- Header File Inclusion */
#include "BT_api.h"
#include "BT_gatt_db_api.h"
#include "gatt_db.h"
#include "appl.h"
#include "appl_ancs_att_server.h"
/* ----------------------------------------- Data Types/ Structures */
typedef struct
{
UCHAR index;
UCHAR length;
}APPL_HRS_OBS_DATA_INFO;
/* --------------------------------------------- Global Definitions */
/** LSB of error code has to be spec defined */
#define APPL_HR_CNTRL_PNT_NOT_SUPPORTED (APPL_ERR_ID | 0x80)
/* --------------------------------------------- Functions */
void appl_ancs_init(void);
void appl_manage_trasnfer (GATT_DB_HANDLE handle, UINT16 config);
void appl_timer_expiry_handler (void *data, UINT16 datalen);
void appl_ancs_connect(DEVICE_HANDLE * dq_handle);
void appl_send_ancs_measurement (APPL_HANDLE * handle);
void appl_ancs_server_reinitialize (void);
void appl_rcv_service_desc (UINT16 config, ATT_UUID uuid, UINT16 value_handle);
void appl_rcv_service_char (ATT_UUID uuid, UINT16 value_handle);
API_RESULT appl_hr_control_point_handler
(
GATT_DB_HANDLE * handle,
ATT_VALUE * value
);
API_RESULT appl_att_callback
(
ATT_HANDLE * handle,
UCHAR event_type,
API_RESULT event_result,
UCHAR * event_data,
UINT16 event_datalen
);
void ancs_mtu_update(APPL_HANDLE * appl_handle, UINT16 t_mtu);
/* Profile handling */
#define APPL_PROFILE_INIT(...) appl_ancs_init()
#define APPL_PROFILE_CONNECT(x) appl_ancs_connect(x)
#define APPL_SEND_MEASUREMENT(x)appl_send_ancs_measurement(x)
#define APPL_PROFILE_DISCONNECT_HANDLER(x) appl_ancs_server_reinitialize()
#define GATT_DB_PROFILE_HANDLER gatt_db_ancs_handler
#define APPL_PROFILE_HVN_NTF_COMPLETE_HANDLER(x, y, z)
#define APPL_PROFILE_HVN_IND_COMPLETE_HANDLER(x, y, z)
#define APPL_PROFILE_MTU_UPDT_COMPLETE_HANDLER(x, y) ancs_mtu_update(x, y)
#define APPL_USE_IDLE_TIMER
#define APPL_IDLE_TIMEOUT 30
#endif /* _H_APPL_ANCS_ */
@@ -0,0 +1,158 @@
//*****************************************************************************
//
//! @file appl_ancs_att_server.h
//!
//! @brief ATT Server Application Header File
//!
//
//*****************************************************************************
//*****************************************************************************
//
// Copyright (c) 2020, Ambiq Micro
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// 3. Neither the name of the copyright holder nor the names of its
// contributors may be used to endorse or promote products derived from this
// software without specific prior written permission.
//
// Third party software included in this distribution is subject to the
// additional license terms as defined in the /docs/licenses directory.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 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.
//
// This is part of revision 2.4.2 of the AmbiqSuite Development Package.
//
//*****************************************************************************
/**
* \file appl_ancs_att_server.h
*
* ATT Server Application Header File
*/
/*
* Copyright (C) 2013. Mindtree Ltd.
* All rights reserved.
*/
#ifndef _H_APPL_ANCS_ATT_SERVER_
#define _H_APPL_ANCS_ATT_SERVER_
/* ----------------------------------------- Header File Inclusion */
#include "BT_api.h"
#include "BT_gatt_db_api.h"
#define APPL_ATT_WRITE_QUEUE_SIZE 10
#define APPL_ATT_MAX_WRITE_BUFFER_SIZE 256 /* 255 */
#define APPL_ATT_MTU ATT_MAX_MTU
#define APPL_SERVER_BUFFER_SIZE 256 /* 256 */
#define APPL_MAX_GROUP_TYPE_QUERIED 5
#define APPL_MAX_HNDL_UUID_LIST_SIZE 5
#define APPL_MAX_HNDL_LIST_SIZE 11
#define APPL_MAX_HNDL_VALUE_SIZE 5
/* ATT PDU Request Length */
#define APPL_ATT_XCNHG_MTU_REQ_LEN 2
#define APPL_ATT_XCNHG_MTU_RSP_LEN 2
#define APPL_ATT_FIND_INFO_REQ_LEN 4
#define APPL_ATT_FIND_INFO_RSP_LEN_1 5
#define APPL_ATT_FIND_INFO_RSP_LEN_2 22
#define ATT_FIND_BY_TYPE_VAL_RSP_LEN1 4
#define ATT_FIND_BY_TYPE_VAL_RSP_LEN2 21
#define APPL_ATT_READ_BY_TYPE_REQ_LEN_1 6
#define APPL_ATT_READ_BY_TYPE_REQ_LEN_2 20
#define ATT_READ_BY_TYPE_RSP_LEN_1 3
#define ATT_READ_BY_TYPE_RSP_LEN_2 22
#define APPL_ATT_READ_REQ_LEN 2
#define APPL_ATT_READ_RSP_LEN_1 0
#define APPL_ATT_READ_RSP_LEN_2 22
#define APPL_ATT_READ_BLOB_REQ_LEN 4
#define APPL_ATT_READ_BLOB_RSP_LEN_1 0
#define APPL_ATT_READ_BLOB_RSP_LEN_2 22
#define APPL_ATT_READ_BY_GROUP_REQ_LEN_1 6
#define APPL_ATT_READ_BY_GROUP_REQ_LEN_2 20
#define APPL_ATT_READ_BY_GROUP_RSP_LEN_1 5
#define APPL_ATT_READ_BY_GROUP_RSP_LEN_2 22
#define APPL_ATT_EXECUTE_WRITE_REQ_LEN 1
#define APPL_ATT_INVALID_LEN 0xFF
#define APPL_MAX_VALID_ATT_PDU_LEN_CHK 7
/** Application Defined error */
#define APPL_ATT_INVALID_OFFSET 0xFFFF
#define ATT_INVALID_ATTR_HANDLE_VAL 0x0000
#define APPL_MAX_MULTIPLE_READ_COUNT 11
#define APPL_CHECK_IF_ATT_REQUEST(type)\
((((((type) > 0x13) && ((type) < 0x16)) ||\
(((type) > 0x1E) && (((type) != ATT_SIGNED_WRITE_CMD) &&\
((type) != ATT_WRITE_CMD)))) || (0x01 == ((type) & 0x01)))? BT_FALSE : BT_TRUE)
#define APPL_ATT_PREPARE_QUEUE_INIT(i)\
appl_att_write_queue[(i)].handle_value.handle = 0;\
appl_att_write_queue[(i)].offset = 0xFFFF;\
appl_att_write_queue[(i)].handle_value.value.len = 0;\
appl_att_write_queue[(i)].handle_value.value.val = NULL;
API_RESULT appl_discover_service
(
/* IN */ ATT_UUID uuid,
/* IN */ UCHAR uuid_frmt
);
API_RESULT appl_write_req
(
/* IN */ ATT_ATTR_HANDLE handle,
/* IN */ ATT_VALUE * value
);
API_RESULT appl_read_req
(
/* IN */ ATT_ATTR_HANDLE handle
);
API_RESULT appl_att_server_init(void);
API_RESULT appl_handle_unsupported_op_code (ATT_HANDLE *handle, UCHAR op_code);
API_RESULT appl_validate_att_pdu_req_len
(
UCHAR att_event,
UINT16 event_datalen
);
#ifdef SMP_DATA_SIGNING
void appl_gatt_signing_complete (API_RESULT status, UCHAR * data, UINT16 datalen);
void appl_gatt_signing_verification_complete
(
API_RESULT status,
UCHAR * data,
UINT16 datalen
);
#endif /* SMP_DATA_SIGNING */
#endif /* _H_APPL_ANCS_ATT_SERVER_ */
@@ -0,0 +1,231 @@
//*****************************************************************************
//
//! @file appl_gap_config_params.c
//!
//! @brief This file contains GAP Configuration Parameters used by the application.
//!
//
//*****************************************************************************
//*****************************************************************************
//
// Copyright (c) 2020, Ambiq Micro
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// 3. Neither the name of the copyright holder nor the names of its
// contributors may be used to endorse or promote products derived from this
// software without specific prior written permission.
//
// Third party software included in this distribution is subject to the
// additional license terms as defined in the /docs/licenses directory.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 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.
//
// This is part of revision 2.4.2 of the AmbiqSuite Development Package.
//
//*****************************************************************************
/**
* \file appl_gap_config_params.c
*
* This file contains GAP Configuration Parameters used by the application.
*/
/*
* Copyright (C) 2013. Mindtree Ltd.
* All rights reserved.
*/
/* --------------------------------------------- Header File Inclusion */
#include "appl_gap.h"
#ifdef ANCS
/* --------------------------------------------- External Global Variables */
/* --------------------------------------------- Exported Global Variables */
/* --------------------------------------------- Static Global Variables */
#if ((defined APPL_GAP_BROADCASTER_SUPPORT) || (defined APPL_GAP_PERIPHERAL_SUPPORT))
/** Advertisement Data Options */
const APPL_GAP_ADV_DATA appl_gap_adv_data[APPL_GAP_MAX_ADV_DATA_OPTIONS] =
{
/* GAP Advertisement Parameters */
{
{
/**
* Flags:
* 0x01: LE Limited Discoverable Mode
* 0x02: LE General Discoverable Mode
* 0x04: BR/EDR Not Supported
* 0x08: Simultaneous LE and BR/EDR to Same Device
* Capable (Controller)
* 0x10: Simultaneous LE and BR/EDR to Same Device
* Capable (Host)
*/
0x02, 0x01,
(BT_AD_FLAGS_LE_GENERAL_DISC_MODE | BT_AD_FLAGS_LE_BR_EDR_SUPPORT),
/**
* Service UUID List:
* Battery Service (0x180F)
* DeviceInformation Service (0x180A)
*/
0x05, 0x03, 0x0F, 0x18, 0x0A, 0x18,
/**
* Shortened Device Name: AM
*/
0x03, 0x08, 0x41, 0x4d,
/**
* List of 16-bit Service Solicitation UUIDs(ANCS UUID)
*/
0x11, 0x15, 0xD0, 0x00, 0x2D, 0x12, 0x1E, 0x4B, 0x0F, 0xA4, 0x99, 0x4E, 0xCE, 0xB5, 0x31, 0xF4, 0x05, 0x79
},
31
}
};
/* Advertisement parameters options */
const APPL_GAP_ADV_PARAM appl_gap_adv_param[APPL_GAP_MAX_ADV_PARAM_OPTIONS] =
{
/* 0 - Normal Advertising Params */
{
32,
32,
7,
0
},
/* 1 - Fast Connection Advertising Params */
{
32,
48,
7,
0
},
/* 2 - Low Power Advertising Params */
{
1600,
4000,
7,
0
}
};
/* Advertisement Table */
APPL_GAP_ADV_INFO appl_gap_adv_table =
{
appl_gap_adv_data,
appl_gap_adv_param,
APPL_GAP_ADV_IDLE
};
#endif /* APPL_GAP_BROADCASTER || APPL_GAP_PERIPHERAL_SUPPORT */
#if ((defined APPL_GAP_OBSERVER_SUPPORT) || (defined APPL_GAP_CENTRAL_SUPPORT))
/* Scan Parameters Option */
const APPL_GAP_SCAN_PARAM appl_gap_scan_param[APPL_GAP_MAX_SCAN_PARAM_OPTIONS] =
{
/* Normal Scan Params */
{
32,
7,
0
},
/* Fast Connection Scan Params */
{
48,
7,
0
},
/* Low Power Scan Params */
{
4000,
7,
0
}
};
/* Scan Table */
APPL_GAP_SCAN_INFO appl_gap_scan_table =
{
appl_gap_scan_param,
APPL_GAP_SCAN_IDLE
};
#endif /* APPL_GAP_OBSERVER_SUPPORT || APPL_GAP_CENTRAL_SUPPORT */
#ifdef APPL_GAP_CENTRAL_SUPPORT
/* Connection Parameters Options */
const APPL_GAP_CONN_PARAM appl_gap_conn_param[APPL_GAP_MAX_CONN_PARAM_OPTIONS] =
{
{
4,
4,
0,
40,
56,
0,
955,
32,
32
}
};
/* GAP Connection Table */
APPL_GAP_CONN_INFO appl_gap_conn_table =
{
appl_gap_conn_param,
APPL_GAP_CONN_IDLE
};
#endif /* APPL_GAP_CENTRAL_SUPPORT */
#endif /* ANCS */
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,157 @@
//*****************************************************************************
//
//! @file gatt_db.h
//!
//! @brief GATT Databse.
//!
//
//*****************************************************************************
//*****************************************************************************
//
// Copyright (c) 2020, Ambiq Micro
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// 3. Neither the name of the copyright holder nor the names of its
// contributors may be used to endorse or promote products derived from this
// software without specific prior written permission.
//
// Third party software included in this distribution is subject to the
// additional license terms as defined in the /docs/licenses directory.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 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.
//
// This is part of revision 2.4.2 of the AmbiqSuite Development Package.
//
//*****************************************************************************
/**
* \file gatt_db.h
*/
/*
* Copyright (C) 2013. Mindtree Ltd.
* All rights reserved.
*/
#ifndef _H_GATT_DB_
#define _H_GATT_DB_
/**
* addgroup gatt_db_module
*/
/**
* defgroup gatt_db_tuneable_param Tuneable Parameters
* {
* This section defines the Tuneable Constants of Data Base Module.
*/
/** Number of Characteristics in the data base */
#define GATT_CHARACTERISTIC_COUNT 13
/** Number of Services in the data base */
#define GATT_SERVICE_COUNT 4
/** Number of Characteristics that are configurable by the client */
#define GATT_DB_MAX_CONFIGUREABLE_CHAR 3
/** Maximum Length of any Characteristic Value/Descriptor */
#define GATT_DB_MAX_VAL_LENGTH 32
#define GATT_VALUE_ARRAY_SIZE 1
#define GATT_CONST_VALUE_ARRAY_SIZE 182
#define GATT_DB_PEER_VALUE_ARRAY_SIZE 4
#define GATT_DB_MAX_ATTRIBUTES 34
#define GATT_UUID_ARRAY_SIZE 54
#define GATT_DB_MAX_TYPE_COUNT 21
#define GATT_DB_MAX_PEER_CONFIGURATION \
(GATT_DB_PEER_VALUE_ARRAY_SIZE * BT_MAX_DEVICE_QUEUE_SIZE)
/** \} */
/** Service Instance Reference */
/** GAP Service */
#define GATT_SER_GAP_INST 0
/** GATT Service */
#define GATT_SER_GATT_INST 1
/** Battery Service */
#define GATT_SER_BATTERY_INST 2
/** DeviceInformation Service */
#define GATT_SER_DEV_INFO_INST 3
/** Characteristic Instance Reference */
/** DeviceName */
#define GATT_CHAR_DEV_NAME_INST 0
/** Appearance */
#define GATT_CHAR_APPEARANCE_INST 1
/** Service Changed */
#define GATT_CHAR_SER_CHNGD_INST 2
/** BatteryLevel */
#define GATT_CHAR_BATTERY_LVL_INST 3
/** ManufacturerName */
#define GATT_CHAR_MAN_NAME_INST 4
/** ModelNumber */
#define GATT_CHAR_MODEL_NO_INST 5
/** SerialNumber */
#define GATT_CHAR_SL_NO_INST 6
/** FirmwareRevision */
#define GATT_CHAR_FW_REV_INST 7
/** HardwareRevision */
#define GATT_CHAR_HW_REV_INST 8
/** SoftwareRevision */
#define GATT_CHAR_SW_REV_INST 9
/** SystemId */
#define GATT_CHAR_SYS_ID_INST 10
/** RegCertDataList */
#define GATT_CHAR_REG_CERT_DATA_INST 11
/** PnPID */
#define GATT_CHAR_PNP_ID_INST 12
#endif /* _H_GATT_DB_ */
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,234 @@
//*****************************************************************************
//
//! @file appl_gap_config_params.c
//!
//! @brief This file contains GAP Configuration Parameters used by the application.
//!
//
//*****************************************************************************
//*****************************************************************************
//
// Copyright (c) 2020, Ambiq Micro
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// 3. Neither the name of the copyright holder nor the names of its
// contributors may be used to endorse or promote products derived from this
// software without specific prior written permission.
//
// Third party software included in this distribution is subject to the
// additional license terms as defined in the /docs/licenses directory.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 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.
//
// This is part of revision 2.4.2 of the AmbiqSuite Development Package.
//
//*****************************************************************************
/**
* \file appl_gap_config_params.c
*
* This file contains GAP Configuration Parameters used by the application.
*/
/*
* Copyright (C) 2013. Mindtree Ltd.
* All rights reserved.
*/
/* --------------------------------------------- Header File Inclusion */
#include "appl_gap.h"
/* --------------------------------------------- External Global Variables */
/* --------------------------------------------- Exported Global Variables */
/* --------------------------------------------- Static Global Variables */
#if ((defined APPL_GAP_BROADCASTER_SUPPORT) || (defined APPL_GAP_PERIPHERAL_SUPPORT))
/** Advertisement Data Options */
const APPL_GAP_ADV_DATA appl_gap_adv_data[APPL_GAP_MAX_ADV_DATA_OPTIONS] =
{
/* GAP Advertisement Parameters */
{
{
/**
* Flags:
* 0x01: LE Limited Discoverable Mode
* 0x02: LE General Discoverable Mode
* 0x04: BR/EDR Not Supported
* 0x08: Simultaneous LE and BR/EDR to Same Device
* Capable (Controller)
* 0x10: Simultaneous LE and BR/EDR to Same Device
* Capable (Host)
*/
0x02, 0x01,
(BT_AD_FLAGS_LE_GENERAL_DISC_MODE | BT_AD_FLAGS_LE_BR_EDR_SUPPORT),
/*! Manufacturer specific data AD type */
0x1A, /*! length */
HCI_AD_TYPE_MANUFACTURER_SPECIFIC_DATA, /*! AD type */
0x4C, /*! Company ID[0] */
0x00, /*! Company ID[1] */
0x02, /*! Device type, this has to be 0x02*/
0x15, /*! Length of vendor advertising data. */
/*! Proximity UUID 16 bytes */
0xe2, 0xc5, 0x6d, 0xb5,
0xdf, 0xfb, 0x48, 0xd2,
0xb0, 0x60, 0xd0, 0xf5,
0xa7, 0x10, 0x96, 0xe0,
/*! Major 0xnnnn */
0x00, 0x00,
/*! Minor 0xnnnn */
0x00, 0x00,
/*! Measured Power */
0xc5
},
30
}
};
/* Advertisement parameters options */
const APPL_GAP_ADV_PARAM appl_gap_adv_param[APPL_GAP_MAX_ADV_PARAM_OPTIONS] =
{
/* 0 - Normal Advertising Params */
{
32,
32,
7,
0
},
/* 1 - Fast Connection Advertising Params */
{
32,
48,
7,
0
},
/* 2 - Low Power Advertising Params */
{
1600,
4000,
7,
0
}
};
/* Advertisement Table */
APPL_GAP_ADV_INFO appl_gap_adv_table =
{
appl_gap_adv_data,
appl_gap_adv_param,
APPL_GAP_ADV_IDLE
};
#endif /* APPL_GAP_BROADCASTER || APPL_GAP_PERIPHERAL_SUPPORT */
#if ((defined APPL_GAP_OBSERVER_SUPPORT) || (defined APPL_GAP_CENTRAL_SUPPORT))
/* Scan Parameters Option */
const APPL_GAP_SCAN_PARAM appl_gap_scan_param[APPL_GAP_MAX_SCAN_PARAM_OPTIONS] =
{
/* Normal Scan Params */
{
32,
7,
0
},
/* Fast Connection Scan Params */
{
48,
7,
0
},
/* Low Power Scan Params */
{
4000,
7,
0
}
};
/* Scan Table */
APPL_GAP_SCAN_INFO appl_gap_scan_table =
{
appl_gap_scan_param,
APPL_GAP_SCAN_IDLE
};
#endif /* APPL_GAP_OBSERVER_SUPPORT || APPL_GAP_CENTRAL_SUPPORT */
#ifdef APPL_GAP_CENTRAL_SUPPORT
/* Connection Parameters Options */
const APPL_GAP_CONN_PARAM appl_gap_conn_param[APPL_GAP_MAX_CONN_PARAM_OPTIONS] =
{
{
4,
4,
0,
40,
56,
0,
955,
32,
32
}
};
/* GAP Connection Table */
APPL_GAP_CONN_INFO appl_gap_conn_table =
{
appl_gap_conn_param,
APPL_GAP_CONN_IDLE
};
#endif /* APPL_GAP_CENTRAL_SUPPORT */
@@ -0,0 +1,25 @@
/**
* \file appl_ibeacon.c
*
* This file contains ibeacon example
*
* Copyright (C) 2013. Mindtree Ltd.
* All rights reserved.
*/
/* --------------------------------------------- Header File Inclusion */
#include "appl.h"
/* --------------------------------------------- Constants */
/* --------------------------------------------- Static Global Variables */
/* --------------------------------------------- Functions */
void appl_ibeacon_init(void)
{
}
@@ -0,0 +1,87 @@
//*****************************************************************************
//
//! @file appl_ibeacon.h
//!
//! @brief Application Header File for iBeacon example.
//!
//
//*****************************************************************************
//*****************************************************************************
//
// Copyright (c) 2020, Ambiq Micro
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// 3. Neither the name of the copyright holder nor the names of its
// contributors may be used to endorse or promote products derived from this
// software without specific prior written permission.
//
// Third party software included in this distribution is subject to the
// additional license terms as defined in the /docs/licenses directory.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 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.
//
// This is part of revision 2.4.2 of the AmbiqSuite Development Package.
//
//*****************************************************************************
/**
* \file appl_ibeacon.h
*
* Application Header File for iBeacon example.
*/
/*
* Copyright (C) 2013. Mindtree Ltd.
* All rights reserved.
*/
#ifndef _H_APPL_HRS_
#define _H_APPL_HRS_
/* ----------------------------------------- Header File Inclusion */
#include "BT_api.h"
#include "BT_gatt_db_api.h"
#include "gatt_db.h"
#include "appl.h"
/* ----------------------------------------- Data Types/ Structures */
/* --------------------------------------------- Functions */
void appl_ibeacon_init(void);
/* Profile handling */
#define APPL_PROFILE_INIT(...) appl_ibeacon_init()
#define APPL_PROFILE_CONNECT(x)
#define APPL_SEND_MEASUREMENT(x)
#define APPL_PROFILE_DISCONNECT_HANDLER(x)
#define GATT_DB_PROFILE_HANDLER
#define APPL_PROFILE_HVN_NTF_COMPLETE_HANDLER(x, y, z)
#define APPL_PROFILE_HVN_IND_COMPLETE_HANDLER(x, y, z)
#define APPL_PROFILE_MTU_UPDT_COMPLETE_HANDLER(x, y)
#define APPL_USE_IDLE_TIMER
#define APPL_IDLE_TIMEOUT 30
#endif /* _H_APPL_HRS_ */
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,167 @@
//*****************************************************************************
//
//! @file gatt_db.h
//!
//! @brief GATT Databse.
//!
//
//*****************************************************************************
//*****************************************************************************
//
// Copyright (c) 2020, Ambiq Micro
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// 3. Neither the name of the copyright holder nor the names of its
// contributors may be used to endorse or promote products derived from this
// software without specific prior written permission.
//
// Third party software included in this distribution is subject to the
// additional license terms as defined in the /docs/licenses directory.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 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.
//
// This is part of revision 2.4.2 of the AmbiqSuite Development Package.
//
//*****************************************************************************
/**
* \file gatt_db.h
*/
/*
* Copyright (C) 2013. Mindtree Ltd.
* All rights reserved.
*/
#ifndef _H_GATT_DB_
#define _H_GATT_DB_
/**
* addgroup gatt_db_module
*/
/**
* defgroup gatt_db_tuneable_param Tuneable Parameters
* {
* This section defines the Tuneable Constants of Data Base Module.
*/
/** Number of Characteristics in the data base */
#define GATT_CHARACTERISTIC_COUNT 16
/** Number of Services in the data base */
#define GATT_SERVICE_COUNT 5
/** Number of Characteristics that are configurable by the client */
#define GATT_DB_MAX_CONFIGUREABLE_CHAR 3
/** Maximum Length of any Characteristic Value/Descriptor */
#define GATT_DB_MAX_VAL_LENGTH 32
#define GATT_VALUE_ARRAY_SIZE 3
#define GATT_CONST_VALUE_ARRAY_SIZE 203
#define GATT_DB_PEER_VALUE_ARRAY_SIZE 6
#define GATT_DB_MAX_ATTRIBUTES 42
#define GATT_UUID_ARRAY_SIZE 62
#define GATT_DB_MAX_TYPE_COUNT 25
#define GATT_DB_MAX_PEER_CONFIGURATION \
(GATT_DB_PEER_VALUE_ARRAY_SIZE * BT_MAX_DEVICE_QUEUE_SIZE)
/** \} */
/** Service Instance Reference */
/** GAP Service */
#define GATT_SER_GAP_INST 0
/** GATT Service */
#define GATT_SER_GATT_INST 1
/** Battery Service */
#define GATT_SER_BATTERY_INST 2
/** DeviceInformation Service */
#define GATT_SER_DEV_INFO_INST 3
/** Heart Rate Service */
#define GATT_SER_HEART_RATE_INST 4
/** Characteristic Instance Reference */
/** DeviceName */
#define GATT_CHAR_DEV_NAME_INST 0
/** Appearance */
#define GATT_CHAR_APPEARANCE_INST 1
/** Service Changed */
#define GATT_CHAR_SER_CHNGD_INST 2
/** BatteryLevel */
#define GATT_CHAR_BATTERY_LVL_INST 3
/** ManufacturerName */
#define GATT_CHAR_MAN_NAME_INST 4
/** ModelNumber */
#define GATT_CHAR_MODEL_NO_INST 5
/** SerialNumber */
#define GATT_CHAR_SL_NO_INST 6
/** FirmwareRevision */
#define GATT_CHAR_FW_REV_INST 7
/** HardwareRevision */
#define GATT_CHAR_HW_REV_INST 8
/** SoftwareRevision */
#define GATT_CHAR_SW_REV_INST 9
/** SystemId */
#define GATT_CHAR_SYS_ID_INST 10
/** RegCertDataList */
#define GATT_CHAR_REG_CERT_DATA_INST 11
/** PnPID */
#define GATT_CHAR_PNP_ID_INST 12
/** HeartRateMeasurement */
#define GATT_CHAR_HR_MSRMNT 13
/** BodySensorLocation */
#define GATT_CHAR_BODY_SNSR_LOC_INST 14
/** HeartRateControlPoint */
#define GATT_CHAR_HR_CNTRL_PNT_INST 15
#endif /* _H_GATT_DB_ */