Skip to content

Commit 05f5c24

Browse files
authored
Merge pull request #2462 from particle-iot/gcc-platform-id/sc-105697
Allow overriding the platform ID on the GCC platform
2 parents 5cfa3ec + 3ed0d52 commit 05f5c24

12 files changed

+142
-8
lines changed

communication/inc/protocol.h

+17
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,13 @@ class Protocol
194194
*/
195195
size_t max_transmit_message_size;
196196

197+
#if PLATFORM_ID == PLATFORM_GCC
198+
/**
199+
* Platform ID.
200+
*/
201+
int platform_id;
202+
#endif
203+
197204
void set_protocol_flags(uint32_t flags)
198205
{
199206
protocol_flags = flags;
@@ -332,6 +339,9 @@ class Protocol
332339
ota_chunk_size(DEFAULT_OTA_CHUNK_SIZE),
333340
system_version(0), // Unknown
334341
max_transmit_message_size(0) // Limited by compile-time maximum
342+
#if PLATFORM_ID == PLATFORM_GCC
343+
, platform_id(PLATFORM_ID)
344+
#endif
335345
{
336346
}
337347

@@ -559,6 +569,13 @@ class Protocol
559569
}
560570
}
561571

572+
#if PLATFORM_ID == PLATFORM_GCC
573+
void set_platform_id(int id)
574+
{
575+
platform_id = id;
576+
}
577+
#endif
578+
562579
inline bool send_time_request()
563580
{
564581
#if HAL_PLATFORM_OTA_PROTOCOL_V3

communication/inc/spark_protocol_functions.h

+7
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,13 @@ extern int decrypt_rsa(const uint8_t* ciphertext, const uint8_t* private_key,
298298

299299
void extract_public_rsa_key(uint8_t* device_pubkey, const uint8_t* device_privkey);
300300

301+
#if PLATFORM_ID == PLATFORM_GCC
302+
/**
303+
* Set the platform ID.
304+
*/
305+
void spark_protocol_set_platform_id(ProtocolFacade* protocol, int id);
306+
#endif
307+
301308
/**
302309
* Retrieves a pointer to a statically allocated instance.
303310
* @return A statically allocated instance of ProtocolFacade.

communication/src/dtls_protocol.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,10 @@ class DTLSProtocol : public Protocol
6767
product_details_t deets;
6868
deets.size = sizeof(deets);
6969
get_product_details(deets);
70-
size_t len = Messages::hello(message.buf(), 0 /* message_id */, flags, PLATFORM_ID, system_version,
70+
#if PLATFORM_ID != PLATFORM_GCC
71+
int platform_id = PLATFORM_ID;
72+
#endif
73+
size_t len = Messages::hello(message.buf(), 0 /* message_id */, flags, platform_id, system_version,
7174
deets.product_id, deets.product_version, device_id, sizeof(device_id), get_max_transmit_message_size(),
7275
max_binary_size, ota_chunk_size, true /* confirmable */);
7376
return len;

communication/src/spark_protocol_functions.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -282,3 +282,10 @@ int spark_protocol_get_status(ProtocolFacade* protocol, protocol_status* status,
282282
ASSERT_ON_SYSTEM_THREAD();
283283
return protocol->get_status(status);
284284
}
285+
286+
#if PLATFORM_ID == PLATFORM_GCC
287+
void spark_protocol_set_platform_id(ProtocolFacade* protocol, int id)
288+
{
289+
protocol->set_platform_id(id);
290+
}
291+
#endif

hal/inc/hal_platform.h

+4
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,10 @@
246246
#define HAL_PLATFORM_DEFAULT_CLOUD_KEEPALIVE_INTERVAL (25000)
247247
#endif // HAL_PLATFORM_DEFAULT_CLOUD_KEEPALIVE_INTERVAL
248248

249+
#ifndef HAL_PLATFORM_CELLULAR_CLOUD_KEEPALIVE_INTERVAL
250+
#define HAL_PLATFORM_CELLULAR_CLOUD_KEEPALIVE_INTERVAL (23 * 60 * 1000)
251+
#endif
252+
249253
#ifndef HAL_SOCKET_HAL_COMPAT_NO_SOCKADDR
250254
#define HAL_SOCKET_HAL_COMPAT_NO_SOCKADDR (0)
251255
#endif // HAL_SOCKET_HAL_COMPAT_NO_SOCKADDR

hal/src/gcc/device_config.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ class ConfigParser
9191
device_options.add_options()
9292
("verbosity,v", po::value<uint16_t>(&config.log_level)->default_value(0)->notifier(range(0,NO_LOG_LEVEL,"verbosity")), "verbosity (0-70)")
9393
("device_id,id", po::value<string>(&config.device_id), "the device ID")
94+
("platform_id", po::value<int>(&config.platform_id)->default_value(PLATFORM_ID), "the platform ID")
9495
("device_key,dk", po::value<string>(&config.device_key)->default_value("device_key.der"), "the filename containing the device private key")
9596
("server_key,sk", po::value<string>(&config.server_key)->default_value("server_key.der"), "the filename containing the server public key")
9697
("state,s", po::value<string>(&config.periph_directory)->default_value("state"), "the directory where device state and peripherals is stored")
@@ -201,5 +202,6 @@ void DeviceConfig::read(Configuration& configuration)
201202
setLoggerLevel(LoggerOutputLevel(NO_LOG_LEVEL-configuration.log_level));
202203

203204
this->protocol = configuration.protocol;
205+
this->platform_id = configuration.platform_id;
204206
}
205207

hal/src/gcc/device_config.h

+2
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ struct Configuration
5353
std::string periph_directory;
5454
uint16_t log_level = 0;
5555
ProtocolFactory protocol = PROTOCOL_LIGHTSSL;
56+
int platform_id;
5657
};
5758

5859

@@ -65,6 +66,7 @@ struct DeviceConfig
6566
uint8_t device_key[1024];
6667
uint8_t server_key[1024];
6768
ProtocolFactory protocol;
69+
int platform_id;
6870

6971
size_t hex2bin(const std::string& hex, uint8_t* dest, size_t destLen);
7072

hal/src/gcc/ota_flash_hal.cpp

+64-3
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,72 @@
77
#include "filesystem.h"
88
#include "bytes2hexbuf.h"
99

10+
namespace {
11+
12+
const hal_module_t g_moduleInfo = {
13+
.bounds = {
14+
.maximum_size = 0x10000000,
15+
.start_address = 0,
16+
.end_address = 0x10000000,
17+
.module_function = MODULE_FUNCTION_MONO_FIRMWARE,
18+
.module_index = 0,
19+
.store = MODULE_STORE_MAIN,
20+
.mcu_identifier = 0,
21+
.location = MODULE_BOUNDS_LOC_INTERNAL_FLASH
22+
},
23+
.info = {
24+
.module_start_address = (const void*)0,
25+
.module_end_address = (const void*)0x00100000,
26+
.reserved = 0,
27+
.flags = 0,
28+
.module_version = MODULE_VERSION,
29+
.platform_id = PLATFORM_ID,
30+
.module_function = MODULE_FUNCTION_MONO_FIRMWARE,
31+
.module_index = 0,
32+
.dependency = {
33+
.module_function = MODULE_FUNCTION_NONE,
34+
.module_index = 0,
35+
.module_version = 0
36+
},
37+
.dependency2 = {
38+
.module_function = MODULE_FUNCTION_NONE,
39+
.module_index = 0,
40+
.module_version = 0
41+
}
42+
},
43+
.crc = {
44+
.crc32 = 0xaabbccdd
45+
},
46+
.suffix = {
47+
.reserved = 0,
48+
.sha = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff,
49+
0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff },
50+
.size = 36
51+
},
52+
.validity_checked = MODULE_VALIDATION_INTEGRITY | MODULE_VALIDATION_DEPENDENCIES | MODULE_VALIDATION_RANGE |
53+
MODULE_VALIDATION_PLATFORM,
54+
.validity_result = MODULE_VALIDATION_INTEGRITY | MODULE_VALIDATION_DEPENDENCIES | MODULE_VALIDATION_RANGE |
55+
MODULE_VALIDATION_PLATFORM,
56+
.module_info_offset = 0
57+
};
58+
59+
} // namespace
60+
1061
int HAL_System_Info(hal_system_info_t* info, bool create, void* reserved)
1162
{
12-
info->platform_id = PLATFORM_ID;
13-
info->module_count = 0;
14-
info->modules = NULL;
63+
if (create) {
64+
const auto module = new(std::nothrow) hal_module_t;
65+
if (!module) {
66+
return SYSTEM_ERROR_NO_MEMORY;
67+
}
68+
memcpy(module, &g_moduleInfo, sizeof(hal_module_t));
69+
module->info.platform_id = deviceConfig.platform_id;
70+
info->modules = module;
71+
info->module_count = 1;
72+
info->platform_id = deviceConfig.platform_id;
73+
} else {
74+
delete info->modules;
75+
}
1576
return 0;
1677
}
1778

system/src/system_cloud_connection.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,13 @@ extern uint8_t feature_cloud_udp;
4444
extern uint32_t particle_key_errors;
4545
volatile bool cloud_socket_aborted = false;
4646

47+
#if HAL_PLATFORM_CELLULAR
48+
static volatile int s_ipv4_cloud_keepalive = HAL_PLATFORM_CELLULAR_CLOUD_KEEPALIVE_INTERVAL;
49+
static volatile int s_ipv6_cloud_keepalive = HAL_PLATFORM_CELLULAR_CLOUD_KEEPALIVE_INTERVAL;
50+
#else
4751
static volatile int s_ipv4_cloud_keepalive = HAL_PLATFORM_DEFAULT_CLOUD_KEEPALIVE_INTERVAL;
4852
static volatile int s_ipv6_cloud_keepalive = HAL_PLATFORM_DEFAULT_CLOUD_KEEPALIVE_INTERVAL;
53+
#endif
4954

5055
using namespace particle::system::cloud;
5156

system/src/system_cloud_internal.cpp

+26
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,17 @@ int getCloudFunctionInfo(size_t index, const char** name) {
249249
return 0;
250250
}
251251

252+
#if PLATFORM_ID == PLATFORM_GCC
253+
int platformIdOverride() {
254+
hal_system_info_t info = {};
255+
info.size = sizeof(info);
256+
SPARK_ASSERT(HAL_System_Info(&info, true /* construct */, nullptr) == 0);
257+
const auto platformId = info.platform_id;
258+
HAL_System_Info(&info, false, nullptr);
259+
return platformId;
260+
}
261+
#endif
262+
252263
} // namespace particle
253264

254265
extern uint8_t feature_cloud_udp;
@@ -952,6 +963,11 @@ void Spark_Protocol_Init(void)
952963

953964
if (!spark_protocol_is_initialized(sp))
954965
{
966+
#if PLATFORM_ID == PLATFORM_GCC
967+
int platformId = platformIdOverride();
968+
spark_protocol_set_platform_id(sp, platformId);
969+
#endif // PLATFORM_ID == PLATFORM_GCC
970+
955971
product_details_t info;
956972
info.size = sizeof(info);
957973
spark_protocol_get_product_details(sp, &info);
@@ -1089,6 +1105,16 @@ void Spark_Protocol_Init(void)
10891105
spark_protocol_communications_handlers(sp, &handlers);
10901106

10911107
registerSystemSubscriptions();
1108+
1109+
#if PLATFORM_ID == PLATFORM_GCC
1110+
bool isCellular = (platformId == PLATFORM_GCC || platformId == PLATFORM_BORON || platformId == PLATFORM_BSOM ||
1111+
platformId == PLATFORM_B5SOM || platformId == PLATFORM_TRACKER || platformId == PLATFORM_ESOMX);
1112+
protocol::connection_properties_t connProp = {};
1113+
connProp.size = sizeof(connProp);
1114+
connProp.keepalive_source = protocol::KeepAliveSource::SYSTEM;
1115+
spark_protocol_set_connection_property(sp, protocol::Connection::PING, isCellular ? HAL_PLATFORM_CELLULAR_CLOUD_KEEPALIVE_INTERVAL :
1116+
HAL_PLATFORM_DEFAULT_CLOUD_KEEPALIVE_INTERVAL, &connProp, nullptr);
1117+
#endif // PLATFORM_ID == PLATFORM_GCC
10921118
}
10931119
}
10941120

system/src/system_cloud_internal.h

+4
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,10 @@ int getCloudVariableInfo(size_t index, const char** name, int* type = nullptr);
224224
size_t cloudFunctionCount();
225225
int getCloudFunctionInfo(size_t index, const char** name);
226226

227+
#if PLATFORM_ID == PLATFORM_GCC
228+
int platformIdOverride();
229+
#endif
230+
227231
} // namespace particle
228232

229233
#ifdef __cplusplus

system/src/system_task.cpp

-4
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,6 @@ void Network_Setup(bool threaded)
106106

107107
//Initialize spark protocol callbacks for all System modes
108108
Spark_Protocol_Init();
109-
110-
#if PLATFORM_ID == PLATFORM_BORON || PLATFORM_ID == PLATFORM_BSOM || PLATFORM_ID == PLATFORM_B5SOM || PLATFORM_ID == PLATFORM_TRACKER || PLATFORM_ID == PLATFORM_ESOMX
111-
system_cloud_set_inet_family_keepalive(AF_INET, HAL_PLATFORM_CELLULAR_CLOUD_KEEPALIVE_INTERVAL, 0);
112-
#endif // PLATFORM_ID == PLATFORM_BORON || PLATFORM_ID == PLATFORM_BSOM || PLATFORM_ID == PLATFORM_B5SOM || PLATFORM_ID == PLATFORM_TRACKER || PLATFORM_ID == PLATFORM_ESOMX
113109
}
114110

115111
int cfod_count = 0;

0 commit comments

Comments
 (0)