Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • card10/firmware
  • annejan/firmware
  • astro/firmware
  • fpletz/firmware
  • gerd/firmware
  • fleur/firmware
  • swym/firmware
  • l/firmware
  • uberardy/firmware
  • wink/firmware
  • madonius/firmware
  • mot/firmware
  • filid/firmware
  • q3k/firmware
  • hauke/firmware
  • Woazboat/firmware
  • pink/firmware
  • mossmann/firmware
  • omniskop/firmware
  • zenox/firmware
  • trilader/firmware
  • Danukeru/firmware
  • shoragan/firmware
  • zlatko/firmware
  • sistason/firmware
  • datenwolf/firmware
  • bene/firmware
  • amedee/firmware
  • martinling/firmware
  • griffon/firmware
  • chris007/firmware
  • adisbladis/firmware
  • dbrgn/firmware
  • jelly/firmware
  • rnestler/firmware
  • mh/firmware
  • ln/firmware
  • penguineer/firmware
  • monkeydom/firmware
  • jens/firmware
  • jnaulty/firmware
  • jeffmakes/firmware
  • marekventur/firmware
  • pete/firmware
  • h2obrain/firmware
  • DooMMasteR/firmware
  • jackie/firmware
  • prof_r/firmware
  • Draradech/firmware
  • Kartoffel/firmware
  • hinerk/firmware
  • abbradar/firmware
  • JustTB/firmware
  • LuKaRo/firmware
  • iggy/firmware
  • ente/firmware
  • flgr/firmware
  • Lorphos/firmware
  • matejo/firmware
  • ceddral7/firmware
  • danb/firmware
  • joshi/firmware
  • melle/firmware
  • fitch/firmware
  • deurknop/firmware
  • sargon/firmware
  • markus/firmware
  • kloenk/firmware
  • lucaswerkmeister/firmware
  • derf/firmware
  • meh/firmware
  • dx/card10-firmware
  • torben/firmware
  • yuvadm/firmware
  • AndyBS/firmware
  • klausdieter1/firmware
  • katzenparadoxon/firmware
  • xiretza/firmware
  • ole/firmware
  • techy/firmware
  • thor77/firmware
  • TilCreator/firmware
  • fuchsi/firmware
  • dos/firmware
  • yrlf/firmware
  • PetePriority/firmware
  • SuperVirus/firmware
  • sur5r/firmware
  • tazz/firmware
  • Alienmaster/firmware
  • flo_h/firmware
  • baldo/firmware
  • mmu_man/firmware
  • Foaly/firmware
  • sodoku/firmware
  • Guinness/firmware
  • ssp/firmware
  • led02/firmware
  • Stormwind/firmware
  • arist/firmware
  • coon/firmware
  • mdik/firmware
  • pippin/firmware
  • royrobotiks/firmware
  • zigot83/firmware
  • mo_k/firmware
106 results
Show changes
Showing
with 3679 additions and 2077 deletions
......@@ -15,6 +15,12 @@ int api_dispatcher_init();
bool api_dispatcher_poll_once();
bool api_dispatcher_poll();
/*
* Check if the other core requested a call or if we are already excuting it.
* Only returns a cached version, without acquiring any locks.
*/
bool api_dispatcher_call_pending();
/*
* Attempt to dispatch a call, if one had been polled using
* api_dispatcher_poll(). Will return 0 if no call was dispatched or the ID of
......@@ -39,6 +45,9 @@ void core1_boot(void);
/* Reset core 1 into a state where it can accept a new payload */
void core1_trigger_reset(void);
/* Check if core 1 is ready for a new payload */
bool core1_is_ready(void);
/* Wait for core 1 to respond that it is ready for a new payload */
void core1_wait_ready(void);
......
......@@ -246,7 +246,7 @@ void __dispatch_isr(api_int_id_t id)
# Generate Dispatcher {{{
with open(args.server, "w") as f_dispatcher:
tmp = """\
#include "modules/log.h"
#include "os/core.h"
#include "{header}"
void __api_dispatch_call(uint32_t id, void*epc__apistub_buffer)
......
#include "api/interrupt-sender.h"
#include "api/common.h"
#include "tmr_utils.h"
static bool int_enabled[EPIC_INT_NUM];
int api_interrupt_trigger(api_int_id_t id)
{
if (id >= EPIC_INT_NUM) {
return -EINVAL;
}
if (int_enabled[id]) {
while (API_CALL_MEM->int_id != (-1))
;
API_CALL_MEM->int_id = id;
TMR_TO_Start(MXC_TMR5, 1, 0);
}
return 0;
}
#include <assert.h>
void api_interrupt_init(void)
{
API_CALL_MEM->int_id = (-1);
for (int i = 0; i < EPIC_INT_NUM; i++) {
int_enabled[i] = false;
}
/* Reset interrupt is always enabled */
int_enabled[EPIC_INT_RESET] = true;
}
int epic_interrupt_enable(api_int_id_t int_id)
bool api_interrupt_is_ready(void)
{
if (int_id >= EPIC_INT_NUM) {
return -EINVAL;
}
int_enabled[int_id] = true;
return 0;
return API_CALL_MEM->int_id == (api_int_id_t)(-1);
}
int epic_interrupt_disable(api_int_id_t int_id)
void api_interrupt_trigger(api_int_id_t id)
{
if (int_id >= EPIC_INT_NUM || int_id == EPIC_INT_RESET) {
return -EINVAL;
}
assert(API_CALL_MEM->int_id == (api_int_id_t)(-1));
int_enabled[int_id] = false;
return 0;
API_CALL_MEM->int_id = id;
TMR_TO_Start(MXC_TMR5, 1, 0);
}
......@@ -2,4 +2,5 @@
#include "api/common.h"
void api_interrupt_init(void);
int api_interrupt_trigger(api_int_id_t id);
bool api_interrupt_is_ready(void);
void api_interrupt_trigger(api_int_id_t id);
/*************************************************************************************************/
/*!
* \file
*
* \brief Application framework main module.
*
* Copyright (c) 2011-2018 Arm Ltd. All Rights Reserved.
* ARM Ltd. confidential and proprietary.
*
* IMPORTANT. Your use of this file is governed by a Software License Agreement
* ("Agreement") that must be accepted in order to download or otherwise receive a
* copy of this file. You may not use or copy this file for any purpose other than
* as described in the Agreement. If you do not agree to all of the terms of the
* Agreement do not use this file and delete all copies in your possession or control;
* if you do not have a copy of the Agreement, you must contact ARM Ltd. prior
* to any use, copying or further distribution of this software.
*/
/*************************************************************************************************/
/* card10:
* copied from: lib/sdk/Libraries/BTLE/stack/ble-profiles/sources/apps/app/app_main.c
*
* Reason: we need to correctly implement AppHandleNumericComparison
*/
/* clang-format off */
/* clang-formet turned off for easier diffing against orginal file */
#include <string.h>
#include "wsf_types.h"
#include "wsf_msg.h"
#include "sec_api.h"
#include "wsf_trace.h"
#include "wsf_timer.h"
#include "wsf_assert.h"
#include "util/bstream.h"
#include "dm_api.h"
#include "app_api.h"
#include "app_main.h"
#include "app_ui.h"
#include "modules/log.h"
/**************************************************************************************************
Global Variables
**************************************************************************************************/
/*! Configuration pointer for advertising */
appAdvCfg_t *pAppAdvCfg;
/*! Configuration pointer for extended and periodic advertising */
appExtAdvCfg_t *pAppExtAdvCfg;
/*! Configuration pointer for slave */
appSlaveCfg_t *pAppSlaveCfg;
/*! Configuration pointer for master */
appMasterCfg_t *pAppMasterCfg;
/*! Configuration pointer for extended master */
appExtMasterCfg_t *pAppExtMasterCfg;
/*! Configuration pointer for security */
appSecCfg_t *pAppSecCfg;
/*! Configuration pointer for connection parameter update */
appUpdateCfg_t *pAppUpdateCfg;
/*! Configuration pointer for discovery */
appDiscCfg_t *pAppDiscCfg;
/*! Configuration pointer for application */
appCfg_t *pAppCfg;
/*! Connection control block array */
appConnCb_t appConnCb[DM_CONN_MAX];
/*! WSF handler ID */
wsfHandlerId_t appHandlerId;
/*! Main control block */
appCb_t appCb;
/*! Configuration structure for incoming request actions */
const appReqActCfg_t appReqActCfg =
{
APP_ACT_ACCEPT /*! Action for the remote connection parameter request */
};
/*! Configuration pointer for incoming request actions on master */
appReqActCfg_t *pAppMasterReqActCfg = (appReqActCfg_t *) &appReqActCfg;
/*! Configurable pointer for incoming request actions on slave */
appReqActCfg_t *pAppSlaveReqActCfg = (appReqActCfg_t *) &appReqActCfg;
/*************************************************************************************************/
/*!
* \brief Process messages from the event handler.
*
* \param pMsg Pointer to message.
*
* \return None.
*/
/*************************************************************************************************/
static void appProcMsg(wsfMsgHdr_t *pMsg)
{
switch(pMsg->event)
{
case APP_BTN_POLL_IND:
appUiBtnPoll();
break;
case APP_UI_TIMER_IND:
appUiTimerExpired(pMsg);
break;
default:
break;
}
}
/*************************************************************************************************/
/*!
* \brief Check the bonded state of a connection.
*
* \param connId DM connection ID.
*
* \return Bonded state.
*/
/*************************************************************************************************/
bool_t appCheckBonded(dmConnId_t connId)
{
WSF_ASSERT((connId > 0) && (connId <= DM_CONN_MAX));
return appConnCb[connId - 1].bonded;
}
/*************************************************************************************************/
/*!
* \brief Check the bond-by-LTK state of a connection.
*
* \param connId DM connection ID.
*
* \return Bond-by-LTK state.
*/
/*************************************************************************************************/
bool_t appCheckBondByLtk(dmConnId_t connId)
{
WSF_ASSERT((connId > 0) && (connId <= DM_CONN_MAX));
return appConnCb[connId - 1].bondByLtk;
}
/*************************************************************************************************/
/*!
* \brief Return the number of existing connections of the given role.
*
* \param role Connection role
*
* \return Number of connections.
*/
/*************************************************************************************************/
uint8_t appNumConns(uint8_t role)
{
appConnCb_t *pCcb = appConnCb;
uint8_t i, j;
for (i = DM_CONN_MAX, j = 0; i > 0; i--, pCcb++)
{
if ((pCcb->connId != DM_CONN_ID_NONE) && (DmConnRole(pCcb->connId) == role))
{
j++;
}
}
return j;
}
/*************************************************************************************************/
/*!
* \brief App framework handler init function called during system initialization.
*
* \param handlerID WSF handler ID for App.
*
* \return None.
*/
/*************************************************************************************************/
void AppInit(void)
{
appHandlerId = WsfOsSetNextHandler(AppHandler);
AppDbInit();
}
/*************************************************************************************************/
/*!
* \brief WSF event handler for app framework.
*
* \param event WSF event mask.
* \param pMsg WSF message.
*
* \return None.
*/
/*************************************************************************************************/
void AppHandler(wsfEventMask_t event, wsfMsgHdr_t *pMsg)
{
if (pMsg != NULL)
{
APP_TRACE_INFO1("App got evt %d", pMsg->event);
if (pMsg->event >= APP_MASTER_MSG_START)
{
/* pass event to master handler */
(*appCb.masterCback)(pMsg);
}
else if (pMsg->event >= APP_SLAVE_MSG_START)
{
/* pass event to slave handler */
(*appCb.slaveCback)(pMsg);
}
else
{
appProcMsg(pMsg);
}
}
else
{
if (event & APP_BTN_DOWN_EVT)
{
AppUiBtnPressed();
}
}
}
/*************************************************************************************************/
/*!
* \brief Handle a passkey request during pairing. If the passkey is to displayed, a
* random passkey is generated and displayed. If the passkey is to be entered
* the user is prompted to enter the passkey.
*
* \param pAuthReq DM authentication requested event structure.
*
* \return None.
*/
/*************************************************************************************************/
void AppHandlePasskey(dmSecAuthReqIndEvt_t *pAuthReq)
{
uint32_t passkey;
uint8_t buf[SMP_PIN_LEN];
if (pAuthReq->display)
{
/* generate random passkey, limit to 6 digit max */
SecRand((uint8_t *) &passkey, sizeof(uint32_t));
passkey %= 1000000;
/* convert to byte buffer */
buf[0] = UINT32_TO_BYTE0(passkey);
buf[1] = UINT32_TO_BYTE1(passkey);
buf[2] = UINT32_TO_BYTE2(passkey);
/* send authentication response to DM */
DmSecAuthRsp((dmConnId_t) pAuthReq->hdr.param, SMP_PIN_LEN, buf);
/* display passkey */
AppUiDisplayPasskey(passkey);
}
else
{
/* prompt user to enter passkey */
AppUiAction(APP_UI_PASSKEY_PROMPT);
}
}
/*************************************************************************************************/
/*!
* \brief Handle a numeric comparison indication during pairing. The confirmation value is
* displayed and the user is prompted to verify that the local and peer confirmation
* values match.
*
* \param pCnfInd DM confirmation indication event structure.
*
* \return None.
*/
/*************************************************************************************************/
void AppHandleNumericComparison(dmSecCnfIndEvt_t *pCnfInd)
{
uint32_t confirm = DmSecGetCompareValue(pCnfInd->confirm);
LOG_INFO("ble", "Confirm Value: %ld", confirm);
/* display confirmation value */
AppUiDisplayConfirmValue(confirm);
/* TODO: Verify that local and peer confirmation values match */
DmSecCompareRsp((dmConnId_t)pCnfInd->hdr.param, TRUE);
}
/*************************************************************************************************/
/*!
* \brief Close the connection with the give connection identifier.
*
* \param connId Connection identifier.
*
* \return None.
*/
/*************************************************************************************************/
void AppConnClose(dmConnId_t connId)
{
DmConnClose(DM_CLIENT_ID_APP, connId, HCI_ERR_REMOTE_TERMINATED);
}
/*************************************************************************************************/
/*!
* \brief Get a list of connection identifiers of open connections.
*
* \param pConnIdList Buffer to hold connection IDs (must be DM_CONN_MAX bytes).
*
* \return Number of open connections.
*
*/
/*************************************************************************************************/
uint8_t AppConnOpenList(dmConnId_t *pConnIdList)
{
appConnCb_t *pCcb = appConnCb;
uint8_t i;
uint8_t pos = 0;
memset(pConnIdList, DM_CONN_ID_NONE, DM_CONN_MAX);
for (i = DM_CONN_MAX; i > 0; i--, pCcb++)
{
if (pCcb->connId != DM_CONN_ID_NONE)
{
pConnIdList[pos++] = pCcb->connId;
}
}
return pos;
}
/*************************************************************************************************/
/*!
* \brief Check if a connection is open.
*
* \return Connection ID of open connection or DM_CONN_ID_NONE if no open connections.
*/
/*************************************************************************************************/
dmConnId_t AppConnIsOpen(void)
{
appConnCb_t *pCcb = appConnCb;
uint8_t i;
for (i = DM_CONN_MAX; i > 0; i--, pCcb++)
{
if (pCcb->connId != DM_CONN_ID_NONE)
{
return pCcb->connId;
}
}
return DM_CONN_ID_NONE;
}
/*************************************************************************************************/
/*!
* \brief Get the device database record handle associated with an open connection.
*
* \param connId Connection identifier.
*
* \return Database record handle or APP_DB_HDL_NONE.
*/
/*************************************************************************************************/
appDbHdl_t AppDbGetHdl(dmConnId_t connId)
{
return appConnCb[connId-1].dbHdl;
}
/*************************************************************************************************/
/*!
* \brief Add device to resolving list.
*
* \param pMsg Pointer to DM callback event message.
* \param connId Connection identifier.
*
* \return None.
*/
/*************************************************************************************************/
void AppAddDevToResList(dmEvt_t *pMsg, dmConnId_t connId)
{
dmSecKey_t *pPeerKey;
appDbHdl_t hdl = appConnCb[connId - 1].dbHdl;
/* if LL Privacy is supported and the peer device has distributed its IRK */
if (HciLlPrivacySupported() && ((pPeerKey = AppDbGetKey(hdl, DM_KEY_IRK, NULL))!= NULL))
{
/* add peer device to resolving list. If all-zero local or peer IRK is used then
LL will only use or accept local or peer identity address respectively. */
DmPrivAddDevToResList(pPeerKey->irk.addrType, pPeerKey->irk.bdAddr, pPeerKey->irk.key,
DmSecGetLocalIrk(), TRUE, pMsg->hdr.param);
}
}
/*************************************************************************************************/
/*!
* \brief Update privacy mode for a given peer device.
*
* \param hdl Database record handle.
*
* \return None.
*/
/*************************************************************************************************/
void AppUpdatePrivacyMode(appDbHdl_t hdl)
{
/* if peer device's been added to resolving list but RPA Only attribute not found on peer device */
if ((hdl != APP_DB_HDL_NONE) && AppDbGetPeerAddedToRl(hdl) && !AppDbGetPeerRpao(hdl))
{
dmSecKey_t *pPeerKey = AppDbGetKey(hdl, DM_KEY_IRK, NULL);
if (pPeerKey != NULL)
{
/* set device privacy mode for this peer device */
DmPrivSetPrivacyMode(pPeerKey->irk.addrType, pPeerKey->irk.bdAddr, DM_PRIV_MODE_DEVICE);
/* make sure resolving list flag cleared */
AppDbSetPeerAddedToRl(hdl, FALSE);
}
}
}
/* clang-format on */
This diff is collapsed.
/*************************************************************************************************/
/*!
* \file
*
* \brief Application framework user interface.
*
* Copyright (c) 2011-2018 Arm Ltd. All Rights Reserved.
* ARM Ltd. confidential and proprietary.
*
* IMPORTANT. Your use of this file is governed by a Software License Agreement
* ("Agreement") that must be accepted in order to download or otherwise receive a
* copy of this file. You may not use or copy this file for any purpose other than
* as described in the Agreement. If you do not agree to all of the terms of the
* Agreement do not use this file and delete all copies in your possession or control;
* if you do not have a copy of the Agreement, you must contact ARM Ltd. prior
* to any use, copying or further distribution of this software.
*/
/*************************************************************************************************/
#include "wsf_types.h"
#include "wsf_os.h"
#include "wsf_trace.h"
#include "app_ui.h"
/* card10:
* copied from: lib/sdk/Libraries/BTLE/stack/ble-profiles/sources/apps/app/common/app_ui.c
*
* Reason: has several user interactions which we likley have to implement
*/
/* clang-format off */
/* clang-formet turned off for easier diffing against orginal file */
/**************************************************************************************************
Global Variables
**************************************************************************************************/
/*! \brief Callback struct */
appUiCback_t appUiCbackTbl;
/*************************************************************************************************/
/*!
* \brief card10 - Should disable encryption. MAXIM bug reported to us in current static library. Requires
* this to be called before the BTLE app starts making advertisements. Avoids encryption
* rendering the frame unreadable.
*
* \return None.
*/
/*************************************************************************************************/
void llc_api_crypto_disable_tx();
/*************************************************************************************************/
/*!
* \brief Perform a user interface action based on the event value passed to the function.
*
* \param event User interface event value.
*
* \return None.
*/
/*************************************************************************************************/
void AppUiAction(uint8_t event)
{
switch (event)
{
case APP_UI_NONE:
/* no action */
break;
case APP_UI_RESET_CMPL:
APP_TRACE_INFO0(">>> Reset complete <<<");
break;
case APP_UI_ADV_START:
llc_api_crypto_disable_tx();
APP_TRACE_INFO0(">>> Advertising started <<<");
break;
case APP_UI_ADV_STOP:
APP_TRACE_INFO0(">>> Advertising stopped <<<");
break;
case APP_UI_SCAN_START:
APP_TRACE_INFO0(">>> Scanning started <<<");
break;
case APP_UI_SCAN_STOP:
APP_TRACE_INFO0(">>> Scanning stopped <<<");
break;
case APP_UI_SCAN_REPORT:
APP_TRACE_INFO0(">>> Scan data received from peer <<<");
break;
case APP_UI_CONN_OPEN:
APP_TRACE_INFO0(">>> Connection opened <<<");
break;
case APP_UI_CONN_CLOSE:
APP_TRACE_INFO0(">>> Connection closed <<<");
break;
case APP_UI_SEC_PAIR_CMPL:
APP_TRACE_INFO0(">>> Pairing completed successfully <<<");
break;
case APP_UI_SEC_PAIR_FAIL:
APP_TRACE_INFO0(">>> Pairing failed <<<");
break;
case APP_UI_SEC_ENCRYPT:
APP_TRACE_INFO0(">>> Connection encrypted <<<");
break;
case APP_UI_SEC_ENCRYPT_FAIL:
APP_TRACE_INFO0(">>> Encryption failed <<<");
break;
case APP_UI_PASSKEY_PROMPT:
APP_TRACE_INFO0(">>> Prompt user to enter passkey <<<");
break;
case APP_UI_ALERT_CANCEL:
APP_TRACE_INFO0(">>> Cancel a low or high alert <<<");
break;
case APP_UI_ALERT_LOW:
APP_TRACE_INFO0(">>> Low alert <<<");
break;
case APP_UI_ALERT_HIGH:
APP_TRACE_INFO0(">>> High alert <<<");
break;
case APP_UI_ADV_SET_START_IND:
APP_TRACE_INFO0(">>> Advertising set(s) started <<<");
break;
case APP_UI_ADV_SET_STOP_IND:
APP_TRACE_INFO0(">>> Advertising set(s) stopped <<<");
break;
case APP_UI_SCAN_REQ_RCVD_IND:
APP_TRACE_INFO0(">>> Scan request received <<<");
break;
case APP_UI_EXT_SCAN_START_IND:
APP_TRACE_INFO0(">>> Extended scanning started <<<");
break;
case APP_UI_EXT_SCAN_STOP_IND:
APP_TRACE_INFO0(">>> Extended scanning stopped <<<");
break;
case APP_UI_PER_ADV_SET_START_IND:
APP_TRACE_INFO0(">>> Periodic advertising set started <<<");
break;
case APP_UI_PER_ADV_SET_STOP_IND:
APP_TRACE_INFO0(">>> Periodic advertising set stopped <<<");
break;
case APP_UI_PER_ADV_SYNC_EST_IND:
APP_TRACE_INFO0(">>> Periodic advertising sync established <<<");
break;
case APP_UI_PER_ADV_SYNC_LOST_IND:
APP_TRACE_INFO0(">>> Periodic advertising sync lost <<<");
break;
default:
break;
}
if (appUiCbackTbl.actionCback)
{
(*appUiCbackTbl.actionCback)(event);
}
}
/*************************************************************************************************/
/*!
* \brief Display a passkey.
*
* \param passkey Passkey to display.
*
* \return None.
*/
/*************************************************************************************************/
void AppUiDisplayPasskey(uint32_t passkey)
{
APP_TRACE_INFO1(">>> Passkey: %d <<<", passkey);
}
/*************************************************************************************************/
/*!
* \brief Display a confirmation value.
*
* \param confirm Confirm value to display.
*
* \return None.
*/
/*************************************************************************************************/
void AppUiDisplayConfirmValue(uint32_t confirm)
{
APP_TRACE_INFO1(">>> Confirm Value: %d <<<", confirm);
}
/*************************************************************************************************/
/*!
* \brief Display an RSSI value.
*
* \param rssi Rssi value to display.
*
* \return None.
*/
/*************************************************************************************************/
void AppUiDisplayRssi(int8_t rssi)
{
APP_TRACE_INFO1(">>> RSSI: %d dBm<<<", rssi);
}
/*************************************************************************************************/
/*!
* \brief Handle a UI timer expiration event.
*
* \param pMsg Pointer to message.
*
* \return None.
*/
/*************************************************************************************************/
void appUiTimerExpired(wsfMsgHdr_t *pMsg)
{
}
/*************************************************************************************************/
/*!
* \brief Perform button press polling. This function is called to handle WSF
* message APP_BTN_POLL_IND.
*
* \return None.
*/
/*************************************************************************************************/
void appUiBtnPoll(void)
{
if (appUiCbackTbl.btnPollCback)
{
(*appUiCbackTbl.btnPollCback)();
}
}
/*************************************************************************************************/
/*!
* \brief Handle a hardware button press. This function is called to handle WSF
* event APP_BTN_DOWN_EVT.
*
* \return None.
*/
/*************************************************************************************************/
void AppUiBtnPressed(void)
{
}
/*************************************************************************************************/
/*!
* \brief Register a callback function to receive application button press events.
*
* \return None.
*
* \note Registered by application to receive button events
*/
/*************************************************************************************************/
void AppUiBtnRegister(appUiBtnCback_t btnCback)
{
appUiCbackTbl.btnCback = btnCback;
}
/*************************************************************************************************/
/*!
* \brief Register a callback function to receive action events.
*
* \return None.
*
* \note Registered by platform
*/
/*************************************************************************************************/
void AppUiActionRegister(appUiActionCback_t actionCback)
{
appUiCbackTbl.actionCback = actionCback;
}
/*************************************************************************************************/
/*!
* \brief Register a callback function to receive APP_BTN_POLL_IND events.
*
* \return None.
*
* \note Registered by platform
*/
/*************************************************************************************************/
void AppUiBtnPollRegister(appUiBtnPollCback_t btnPollCback)
{
appUiCbackTbl.btnPollCback = btnPollCback;
}
/*************************************************************************************************/
/*!
* \brief Play a sound.
*
* \param pSound Pointer to sound tone/duration array.
*
* \return None.
*/
/*************************************************************************************************/
void AppUiSoundPlay(const appUiSound_t *pSound)
{
}
/*************************************************************************************************/
/*!
* \brief Stop the sound that is currently playing.
*
* \return None.
*/
/*************************************************************************************************/
void AppUiSoundStop(void)
{
}
/*************************************************************************************************/
/*!
* \brief Button test function-- for test purposes only.
*
* \return None.
*/
/*************************************************************************************************/
void AppUiBtnTest(uint8_t btn)
{
if (appUiCbackTbl.btnCback)
{
(*appUiCbackTbl.btnCback)(btn);
}
}
/* clang-format on */
This diff is collapsed.
#include "ble_api.h"
#include "epicardium.h"
#include "os/core.h"
#include "os/config.h"
#include "wsf_types.h"
#include "util/bstream.h"
#include "wsf_msg.h"
#include "wsf_trace.h"
#include "app_api.h"
#include "app_db.h"
#include "svc_ch.h"
#include "profiles/gap_api.h"
#include <stdio.h>
#include <string.h>
#define DEFAULT_ADV_INTERVAL_US 500000
/*! configurable parameters for advertising */
static appAdvCfg_t bleAdvCfg = {
{ 0, 0 }, /*! Advertising durations in ms */
{ DEFAULT_ADV_INTERVAL_US / 625,
0 } /*! Advertising intervals in 0.625 ms units */
};
static bool tainted;
/**************************************************************************************************
Advertising Data
**************************************************************************************************/
/* clang-format off */
/*! advertising data, discoverable mode */
static const uint8_t bleAdvDataDisc[] = {
/*! flags */
2, /*! length */
DM_ADV_TYPE_FLAGS, /*! AD type */
DM_FLAG_LE_LIMITED_DISC | /*! flags */
DM_FLAG_LE_BREDR_NOT_SUP,
3,
DM_ADV_TYPE_APPEARANCE,
UINT16_TO_BYTES(CH_APPEAR_WATCH),
/*! service UUID list */
17,
DM_ADV_TYPE_128_UUID_PART,
CARD10_UUID_SUFFIX,
0x0,
CARD10_UUID_PREFIX,
2, /*! length */
DM_ADV_TYPE_TX_POWER, /*! AD type */
0, /*! tx power */
};
/*! advertising data, discoverable mode with HID service*/
static const uint8_t bleAdvDataDiscHID[] = {
/*! flags */
2, /*! length */
DM_ADV_TYPE_FLAGS, /*! AD type */
DM_FLAG_LE_LIMITED_DISC | /*! flags */
DM_FLAG_LE_BREDR_NOT_SUP,
3,
DM_ADV_TYPE_APPEARANCE,
UINT16_TO_BYTES(CH_APPEAR_WATCH),
/*! service UUID list */
17,
DM_ADV_TYPE_128_UUID_PART,
CARD10_UUID_SUFFIX,
0x0,
CARD10_UUID_PREFIX,
3, /*! length */
DM_ADV_TYPE_16_UUID_PART, /*! AD type */
UINT16_TO_BYTES(ATT_UUID_HID_SERVICE)
};
/*! scan data, discoverable mode */
uint8_t bleScanDataDisc[] = {
/*! device name */
14, /*! length */
DM_ADV_TYPE_LOCAL_NAME, /*! AD type */
'c','a','r','d','1','0','-','0','0','0','0','0','0',
3, /*! length */
DM_ADV_TYPE_16_SOLICIT, /*! AD type */
UINT16_TO_BYTES(ATT_UUID_CURRENT_TIME_SERVICE),
};
/* clang-format on */
/*! advertising data, connectable mode */
static const uint8_t bleAdvDataConn[] = {
/*! flags */
2, /*! length */
DM_ADV_TYPE_FLAGS, /*! AD type */
DM_FLAG_LE_BREDR_NOT_SUP,
};
static uint8_t advertising_mode = APP_MODE_NONE;
static uint8_t advertising_mode_target = APP_MODE_NONE;
void ble_adv_proc_msg(bleMsg_t *pMsg)
{
switch (pMsg->hdr.event) {
case DM_ADV_START_IND:
LOG_INFO(
"ble",
"Advertisement started %u %u",
advertising_mode,
advertising_mode_target
);
if (advertising_mode != advertising_mode_target ||
advertising_mode_target == APP_MODE_NONE) {
AppAdvStop();
}
break;
case DM_ADV_STOP_IND:
LOG_INFO(
"ble",
"Advertisement stopped %u %u",
advertising_mode,
advertising_mode_target
);
if (advertising_mode != advertising_mode_target) {
advertising_mode = advertising_mode_target;
AppAdvStart(advertising_mode);
}
break;
case DM_CONN_CLOSE_IND:
/* Stack overwrites advertising mode after connection close.
* Force our desired mode.
*/
advertising_mode = APP_MODE_NONE;
AppAdvStop();
break;
};
}
void ble_adv_init(void)
{
char buf[32];
char a, b, c, d, e, f, K;
/* clang-format off */
int result = epic_config_get_string("ble_mac", buf, sizeof(buf));
if (result == 0) {
if (sscanf(buf,
"%c%c:%c%c:%c%c:%c%c:%c%c:%c%c",
&K, &K, &K, &K, &K, &K,
&a, &b, &c, &d, &e, &f) == 12) {
bleScanDataDisc[9] = a;
bleScanDataDisc[10] = b;
bleScanDataDisc[11] = c;
bleScanDataDisc[12] = d;
bleScanDataDisc[13] = e;
bleScanDataDisc[14] = f;
}
}
/* clang-format on */
pAppAdvCfg = (appAdvCfg_t *)&bleAdvCfg;
}
void ble_adv_setup(void)
{
/* set advertising and scan response data for discoverable mode */
if (config_get_boolean_with_default("ble_hid_enable", false)) {
AppAdvSetData(
APP_ADV_DATA_DISCOVERABLE,
sizeof(bleAdvDataDiscHID),
(uint8_t *)bleAdvDataDiscHID
);
} else {
AppAdvSetData(
APP_ADV_DATA_DISCOVERABLE,
sizeof(bleAdvDataDisc),
(uint8_t *)bleAdvDataDisc
);
}
AppAdvSetData(
APP_SCAN_DATA_DISCOVERABLE,
sizeof(bleScanDataDisc),
(uint8_t *)bleScanDataDisc
);
/* set advertising and scan response data for connectable mode */
AppAdvSetData(
APP_ADV_DATA_CONNECTABLE,
sizeof(bleAdvDataConn),
(uint8_t *)bleAdvDataConn
);
AppAdvSetData(APP_SCAN_DATA_CONNECTABLE, 0, NULL);
bleAdvCfg.advInterval[0] = DEFAULT_ADV_INTERVAL_US / 625;
}
void ble_adv_set_interval(uint32_t interval_us)
{
bleAdvCfg.advInterval[0] = interval_us / 625;
tainted = true;
}
void ble_adv_stop(void)
{
if (advertising_mode != APP_MODE_NONE) {
advertising_mode_target = APP_MODE_NONE;
advertising_mode = APP_MODE_NONE;
AppAdvStop();
}
}
static void adv_start(uint8_t mode)
{
if (advertising_mode != APP_MODE_NONE) {
/* We need to stop advertising in between or the
* adv set will not be changed.
* Also need to wait for the stop operation to finish
* before we can start again
* Also need to set the variables first as we don't
* have a lock on the stack.*/
advertising_mode_target = mode;
advertising_mode = APP_MODE_NONE;
AppAdvStop();
} else {
advertising_mode = mode;
advertising_mode_target = mode;
AppAdvStart(advertising_mode);
}
tainted = false;
}
void ble_adv_start(uint8_t mode)
{
adv_start(mode);
tainted = true;
}
void ble_adv_discoverable(bool discoverable)
{
if (discoverable) {
if (advertising_mode != APP_MODE_DISCOVERABLE || tainted) {
LOG_INFO("ble", "Making bondable and discoverable");
adv_start(APP_MODE_DISCOVERABLE);
}
} else {
/* TODO: This does way more than the function name indicates */
if (AppDbCheckBonded()) {
if (advertising_mode != APP_MODE_CONNECTABLE ||
tainted) {
LOG_INFO("ble", "Bonded. Making connectable");
adv_start(APP_MODE_CONNECTABLE);
}
} else {
LOG_INFO("ble", "Not bonded. Stop advertising");
ble_adv_stop();
}
}
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.