Skip to content

Commit 7436867

Browse files
manoelramonintelcalvinatintel
authored andcommitted
ATLEDGE-358 - BLE Broadcast name must read the product name in the OTP
1 parent 94ea922 commit 7436867

File tree

6 files changed

+73
-12
lines changed

6 files changed

+73
-12
lines changed

libraries/CurieBle/examples/AutomationIO/AutomationIO.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
* For more information: https://developer.bluetooth.org/gatt/services/Pages/ServicesHome.aspx
3030
*/
3131

32-
/* Device name: Appears in advertising packets. Must not exceed 16 characters in length */
32+
/* Device name: Appears in advertising packets. Must not exceed 20 characters in length */
3333
#define DEVICE_NAME "AE_IO"
3434
/* UUID for Automation I/O service */
3535
#define SERVICE_UUID_AUTOMATIONIO (0x1815)

libraries/CurieBle/examples/BatteryMonitor/BatteryMonitor.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ void setup() {
109109
/* Set a name for the BLE device
110110
* We give it an arbitrary name which will appear in advertising packets
111111
* and can be used by remote peers to identify this BLE device
112-
* The name can be changed but must not exceed 16 characters in length */
112+
* The name can be changed but must not exceed 20 characters in length */
113113
CHECK_STATUS(bleDevice.setName("AE_BATTMON"));
114114

115115
/* First, initialise the BLE device */

libraries/CurieBle/src/BleDevice.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ class BlePeripheral {
9191
* If broadcast name is not set, a default name will be used instead
9292
*
9393
* @param name User-defined name string for this device. Truncated if
94-
* more than maximum allowed string length (16 bytes).
94+
* more than maximum allowed string length (20 bytes).
9595
*
9696
* @note This method must be called before the init method
9797
*/
@@ -101,7 +101,7 @@ class BlePeripheral {
101101
* Get the current broadcast name for the BLE Peripheral Device
102102
*
103103
* @param name Array to be filled with a copy of the name string.
104-
* Array size must be at least 17 bytes.
104+
* Array size must be at least 20 bytes.
105105
*/
106106
void getName(char name[]) const;
107107

libraries/CurieBle/src/internal/ble_client.c

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
#include "infra/ipc_uart.h"
4747

4848
#include "ble_client.h"
49+
#include "platform.h"
4950

5051
enum {
5152
UNIT_0_625_MS = 625, /**< Number of microseconds in 0.625 milliseconds. */
@@ -402,14 +403,47 @@ void ble_client_get_factory_config(ble_addr_t *bda, char *name)
402403

403404
/* Set a default name if one has not been specified */
404405
if (name) {
405-
char *suffix = name + strlen(BLE_DEVICE_NAME_DEFAULT_PREFIX);
406-
strcpy(name, BLE_DEVICE_NAME_DEFAULT_PREFIX);
407-
if (bda && bda->type != BLE_DEVICE_ADDR_INVALID) {
406+
407+
// Need to check in the OTP if there is some board name set
408+
// If yes, let's read it, otherwise let's keep the default
409+
// name set in BLE_DEVICE_NAME_DEFAULT_PREFIX
410+
const struct customer_data* otp_data_ptr = (struct customer_data*)(FACTORY_DATA_ADDR + 0x200);
411+
char *suffix;
412+
413+
// checking the presence of key patterns
414+
if ((otp_data_ptr->patternKeyStart == PATTERN_KEY_START) &&
415+
(otp_data_ptr->patternKeyEnd == PATTERN_KEY_END))
416+
{
417+
// The board name is with OTP ar programmed
418+
uint8_t len = otp_data_ptr->board_name_len;
419+
420+
// We need to reserve 5 bytes for '-' and 4 last MAC address in ASCII
421+
if (len > BLE_MAX_DEVICE_NAME - 5) len = BLE_MAX_DEVICE_NAME - 5;
422+
strncpy(name, (const char *)otp_data_ptr->board_name, len);
423+
suffix = name + len;
424+
}
425+
else
426+
{
427+
// There is no board name in the OTP area
428+
suffix = name + strlen(BLE_DEVICE_NAME_DEFAULT_PREFIX);
429+
strcpy(name, BLE_DEVICE_NAME_DEFAULT_PREFIX);
430+
}
431+
432+
// Adding the four last digits of MAC address separated by '-' sufix
433+
if (bda && bda->type != BLE_DEVICE_ADDR_INVALID)
434+
{
408435
*suffix++ = '-';
409-
BYTE_TO_STR(suffix, p_oem->bt_address[4]);
410-
BYTE_TO_STR(suffix, p_oem->bt_address[5]);
436+
BYTE_TO_STR(suffix, p_oem->bt_address[4]);
437+
BYTE_TO_STR(suffix, p_oem->bt_address[5]);
438+
*suffix = 0; /* NULL-terminate the string. Note the macro BYTE_TO_STR
439+
automatically move the pointer */
440+
}
441+
else
442+
{
443+
/* This code segment will be only reached if Curie module was not
444+
provisioned properly with a BLE MAC address*/
445+
*suffix++ = 0; /* NULL-terminate the string */
411446
}
412-
*suffix = 0; /* NULL-terminate the string */
413447
}
414448
}
415449

system/libarc32_edu/framework/include/infra/factory_data.h

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@
5151
* the factory_data struct is modified */
5252
#define FACTORY_DATA_VERSION 0x01
5353

54+
/** Key Patterns in the OTP area */
55+
#define PATTERN_KEY_START 0xA5A5A5A5
56+
#define PATTERN_KEY_END 0x5A5A5A5A
57+
const char INVALID_SN_F[4] = {0xFF, 0xFF, 0xFF, 0xFF};
58+
const char INVALID_SN_0[4] = {0,0,0,0};
59+
5460
enum hardware_type {
5561
EVT = 0x00, /*!< Engineering hardware */
5662
DVT = 0x04, /*!< Comes after EVT */
@@ -140,7 +146,28 @@ struct customer_data {
140146
* hexadecimal value, left-padded */
141147
uint8_t product_hw_ver[4];
142148

143-
uint8_t reserved[492];
149+
uint8_t reserved[12];
150+
151+
uint8_t board_name[32];
152+
153+
uint8_t vendor_name[32];
154+
155+
uint32_t product_sn_len;
156+
157+
uint32_t board_name_len;
158+
159+
uint32_t vendor_name_len;
160+
161+
uint8_t reserved_1[388];
162+
163+
uint32_t patternKeyStart;
164+
165+
uint32_t blockVersionHi;
166+
167+
uint32_t blockVersionLow;
168+
169+
uint32_t patternKeyEnd;
170+
144171
} __packed;
145172

146173
/**

system/libarc32_edu/framework/src/services/ble/ble_protocol.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
*
4141
* Bluetooth SIG defined macros and enum extracted from Bluetooth Spec 4.2
4242
*/
43-
#define BLE_MAX_DEVICE_NAME 16 /**< Max BLE device name length, spec size: 248 */
43+
#define BLE_MAX_DEVICE_NAME 20 /**< Max BLE device name length, spec size: 248 */
4444
#define BLE_MAX_ADV_SIZE 31
4545

4646
/** Advertising Data Type. */

0 commit comments

Comments
 (0)