Skip to content
Snippets Groups Projects
Commit 2766e2f1 authored by danukeru's avatar danukeru Committed by schneider
Browse files

During startup of the BLE, the advert name is pulled off the random bytes of the mac in mac.txt.

parent 7df76031
Branches
No related tags found
No related merge requests found
...@@ -90,16 +90,13 @@ static void WsfInit(void) ...@@ -90,16 +90,13 @@ static void WsfInit(void)
/* TODO: We need a source of MACs */ /* TODO: We need a source of MACs */
static void setAddress(void) static void setAddress(void)
{ {
uint8_t bdAddr[6] = { 0x02, 0x02, 0x44, 0x8B, 0x05, 0x00 }; uint8_t bdAddr[6] = { 0xCA, 0x4D, 0x10, 0x00, 0x00, 0x00 };
char buf[32]; char buf[32];
int result = fs_read_text_file("mac.txt", buf, sizeof(buf)); int result = fs_read_text_file("mac.txt", buf, sizeof(buf));
if (result == -1) { if (result == -1) {
APP_TRACE_INFO0("mac.txt not found, generating random MAC"); APP_TRACE_INFO0("mac.txt not found, generating random MAC");
bdAddr[0] = 0xCA;
bdAddr[1] = 0x4D;
bdAddr[2] = 0x10;
epic_trng_read(bdAddr + 3, 3); epic_trng_read(bdAddr + 3, 3);
sprintf(buf, sprintf(buf,
"%02x:%02x:%02x:%02x:%02x:%02x\n", "%02x:%02x:%02x:%02x:%02x:%02x\n",
...@@ -123,7 +120,7 @@ static void setAddress(void) ...@@ -123,7 +120,7 @@ static void setAddress(void)
bdAddr[4] = b; bdAddr[4] = b;
bdAddr[5] = a; bdAddr[5] = a;
} }
LOG_INFO( LOG_INFO(
"ble", "ble",
"Setting MAC address to %02X:%02X:%02X:%02X:%02X:%02X", "Setting MAC address to %02X:%02X:%02X:%02X:%02X:%02X",
......
...@@ -13,9 +13,11 @@ ...@@ -13,9 +13,11 @@
*/ */
/* clang-format off */ /* clang-format off */
/* clang-formet turned off for easier diffing against orginal file */ /* clang-formet turned off for easier diffing against orginal file */
#include <stdio.h>
#include <string.h> #include <string.h>
#include "wsf_types.h" #include "wsf_types.h"
#include "util/bstream.h" #include "util/bstream.h"
#include "fs_util.h"
#include "wsf_msg.h" #include "wsf_msg.h"
#include "wsf_trace.h" #include "wsf_trace.h"
#include "hci_api.h" #include "hci_api.h"
...@@ -155,12 +157,12 @@ static const uint8_t bleAdvDataDisc[] = ...@@ -155,12 +157,12 @@ static const uint8_t bleAdvDataDisc[] =
}; };
/*! scan data, discoverable mode */ /*! scan data, discoverable mode */
static const uint8_t bleScanDataDisc[] = uint8_t bleScanDataDisc[] =
{ {
/*! device name */ /*! device name */
7, /*! length */ 14, /*! length */
DM_ADV_TYPE_LOCAL_NAME, /*! AD type */ DM_ADV_TYPE_LOCAL_NAME, /*! AD type */
'c','a','r','d','1','0' 'c','a','r','d','1','0','-','0','0','0','0','0','0'
}; };
/************************************************************************************************** /**************************************************************************************************
...@@ -323,6 +325,22 @@ static void bleClose(bleMsg_t *pMsg) ...@@ -323,6 +325,22 @@ static void bleClose(bleMsg_t *pMsg)
/*************************************************************************************************/ /*************************************************************************************************/
static void bleSetup(bleMsg_t *pMsg) static void bleSetup(bleMsg_t *pMsg)
{ {
char buf[32];
char a, b, c, d, e, f;
if (fs_read_text_file("mac.txt", buf, sizeof(buf)))
{
if (sscanf(buf, "**:**:**:%c%c:%c%c:%c%c", &a, &b, &c, &d, &e, &f) == 6)
{
bleScanDataDisc[9] = a;
bleScanDataDisc[10] = b;
bleScanDataDisc[11] = c;
bleScanDataDisc[12] = d;
bleScanDataDisc[13] = e;
bleScanDataDisc[14] = f;
}
}
/* set advertising and scan response data for discoverable mode */ /* set advertising and scan response data for discoverable mode */
AppAdvSetData(APP_ADV_DATA_DISCOVERABLE, sizeof(bleAdvDataDisc), (uint8_t *) bleAdvDataDisc); AppAdvSetData(APP_ADV_DATA_DISCOVERABLE, sizeof(bleAdvDataDisc), (uint8_t *) bleAdvDataDisc);
AppAdvSetData(APP_SCAN_DATA_DISCOVERABLE, sizeof(bleScanDataDisc), (uint8_t *) bleScanDataDisc); AppAdvSetData(APP_SCAN_DATA_DISCOVERABLE, sizeof(bleScanDataDisc), (uint8_t *) bleScanDataDisc);
......
...@@ -2,6 +2,9 @@ source init.gdb ...@@ -2,6 +2,9 @@ source init.gdb
set confirm off set confirm off
mon max32xxx mass_erase 0
mon max32xxx mass_erase 1
echo #### BOOTLOADER ####\n echo #### BOOTLOADER ####\n
load build/bootloader/bootloader.elf load build/bootloader/bootloader.elf
echo #### EPICARDIUM ####\n echo #### EPICARDIUM ####\n
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment