Skip to content

Commit 941ebef

Browse files
keeramistechnobly
authored andcommitted
[gen2][supply secure] system
1 parent f12f66a commit 941ebef

18 files changed

+21
-284
lines changed

hal/src/newhal/ota_flash_hal_stm32f2xx.h

Whitespace-only changes.

system/inc/system_cloud.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -147,29 +147,29 @@ inline void cloud_disconnect(unsigned flags, System_Reset_Reason resetReason) {
147147
cloud_disconnect(flags, CLOUD_DISCONNECT_REASON_SYSTEM_RESET, NETWORK_DISCONNECT_REASON_NONE, resetReason, 0);
148148
}
149149

150-
#if PLATFORM_ID==3
150+
#if PLATFORM_ID == PLATFORM_GCC
151151
// avoid a c-linkage incompatible with C error on newer versions of gcc
152152
String spark_deviceID(void);
153-
#endif
153+
#endif // PLATFORM_ID == PLATFORM_GCC
154154

155155
#ifdef __cplusplus
156156
extern "C" {
157157
#endif
158158

159-
#if PLATFORM_ID!=3
159+
#if PLATFORM_ID != PLATFORM_GCC
160160
String spark_deviceID(void);
161-
#endif
161+
#endif // PLATFORM_ID != PLATFORM_GCC
162162

163163
class String;
164164

165165

166166
#if defined(PLATFORM_ID)
167167

168-
#if !defined(UNIT_TEST) && PLATFORM_ID !=3 && PLATFORM_ID != 20
168+
#if !defined(UNIT_TEST) && PLATFORM_ID != PLATFORM_GCC
169169
PARTICLE_STATIC_ASSERT(spark_data_typedef_is_1_byte, sizeof(Spark_Data_TypeDef)==1);
170-
#endif
170+
#endif // !defined(UNIT_TEST) && PLATFORM_ID != PLATFORM_GCC
171171

172-
#endif
172+
#endif // defined(PLATFORM_ID)
173173

174174
const uint32_t PUBLISH_EVENT_FLAG_PUBLIC = 0x0;
175175
const uint32_t PUBLISH_EVENT_FLAG_PRIVATE = 0x1;
@@ -374,7 +374,7 @@ extern const unsigned char backup_tcp_public_server_address[18];
374374

375375
#if HAL_PLATFORM_CELLULAR || HAL_PLATFORM_NCP
376376
#define TIMING_FLASH_UPDATE_TIMEOUT (300000) // 300sec
377-
#else // HAL_PLATFORM_CELLULAR || HAL_PLATFORM_NCP
377+
#else // likely newhal and gcc
378378
#define TIMING_FLASH_UPDATE_TIMEOUT (30000) // 30sec
379379
#endif // HAL_PLATFORM_CELLULAR || HAL_PLATFORM_NCP
380380

system/inc/system_network.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ typedef enum network_ready_type {
4040
} network_ready_type;
4141
/**
4242
* network_handle_t used to differentiate between two networks
43-
* on the same device, e.g. WLAN and AP modes on Photon.
43+
* on the same device
4444
*/
4545
typedef network_interface_t network_handle_t;
4646
const network_interface_t NIF_DEFAULT = 0;

system/inc/system_sleep_configuration.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ class SystemSleepConfigurationHelper {
9797
}
9898
wakeup = wakeupSourceFeatured(HAL_WAKEUP_SOURCE_TYPE_GPIO, wakeup->next);
9999
}
100-
#endif
100+
#endif // HAL_PLATFORM_FUELGAUGE_MAX17043
101101
return false;
102102
}
103103

system/src/build.mk

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,6 @@ CPPSRC += $(call target_files,src/,*.cpp)
1515
# ASM source files included in this build.
1616
ASRC +=
1717

18-
ifeq ($(PLATFORM_ID),6)
19-
CFLAGS += -DLOG_COMPILE_TIME_LEVEL=LOG_LEVEL_NONE
20-
endif
21-
22-
ifeq ($(PLATFORM_ID),8)
23-
CFLAGS += -DLOG_COMPILE_TIME_LEVEL=LOG_LEVEL_NONE
24-
endif
25-
2618
INCLUDE_DIRS += $(TARGET_SRC_PATH)
2719
INCLUDE_DIRS += $(TARGET_SRC_PATH)/control/proto
2820

system/src/control/config.cpp

Lines changed: 2 additions & 127 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@
3636

3737
#if HAL_PLATFORM_NRF52840
3838
#include "ota_flash_hal_impl.h"
39-
#else
40-
#include "ota_flash_hal_stm32f2xx.h"
4139
#endif
4240

4341
#if HAL_PLATFORM_NCP
@@ -240,131 +238,8 @@ int echo(ctrl_request* req) {
240238
return 0;
241239
}
242240

243-
#if !HAL_PLATFORM_NRF52840
244-
245-
int handleSetSecurityKeyRequest(ctrl_request* req) {
246-
particle_ctrl_SetSecurityKeyRequest pbReq = {};
247-
DecodedString pbKey(&pbReq.data);
248-
int ret = decodeRequestMessage(req, particle_ctrl_SetSecurityKeyRequest_fields, &pbReq);
249-
if (ret == 0) {
250-
ret = store_security_key_data((security_key_type)pbReq.type, pbKey.data, pbKey.size);
251-
}
252-
return ret;
253-
}
254-
255-
int handleGetSecurityKeyRequest(ctrl_request* req) {
256-
particle_ctrl_GetSecurityKeyRequest pbReq = {};
257-
int ret = decodeRequestMessage(req, particle_ctrl_GetSecurityKeyRequest_fields, &pbReq);
258-
if (ret == 0) {
259-
particle_ctrl_GetSecurityKeyReply pbRep = {};
260-
EncodedString pbKey(&pbRep.data);
261-
ret = lock_security_key_data((security_key_type)pbReq.type, &pbKey.data, &pbKey.size);
262-
if (ret == 0) {
263-
ret = encodeReplyMessage(req, particle_ctrl_GetSecurityKeyReply_fields, &pbRep);
264-
unlock_security_key_data((security_key_type)pbReq.type);
265-
}
266-
}
267-
268-
return ret;
269-
}
270-
271-
int handleSetServerAddressRequest(ctrl_request* req) {
272-
particle_ctrl_SetServerAddressRequest pbReq = {};
273-
int ret = decodeRequestMessage(req, particle_ctrl_SetServerAddressRequest_fields, &pbReq);
274-
if (ret == 0) {
275-
ServerAddress addr = {};
276-
// Check if the address string contains an IP address
277-
// TODO: Move IP address parsing/encoding to separate functions
278-
unsigned n1 = 0, n2 = 0, n3 = 0, n4 = 0;
279-
if (sscanf(pbReq.address, "%u.%u.%u.%u", &n1, &n2, &n3, &n4) == 4) {
280-
addr.addr_type = IP_ADDRESS;
281-
addr.ip = ((n1 & 0xff) << 24) | ((n2 & 0xff) << 16) | ((n3 & 0xff) << 8) | (n4 & 0xff);
282-
} else {
283-
const size_t n = strlen(pbReq.address);
284-
if (n < sizeof(ServerAddress::domain)) {
285-
addr.addr_type = DOMAIN_NAME;
286-
addr.length = n;
287-
memcpy(addr.domain, pbReq.address, n);
288-
} else {
289-
ret = SYSTEM_ERROR_TOO_LARGE;
290-
}
291-
}
292-
if (ret == 0) {
293-
addr.port = pbReq.port;
294-
ret = store_server_address((server_protocol_type)pbReq.protocol, &addr);
295-
}
296-
}
297-
return ret;
298-
}
299-
300-
int handleGetServerAddressRequest(ctrl_request* req) {
301-
particle_ctrl_GetServerAddressRequest pbReq = {};
302-
int ret = decodeRequestMessage(req, particle_ctrl_GetServerAddressRequest_fields, &pbReq);
303-
if (ret == 0) {
304-
ServerAddress addr = {};
305-
ret = load_server_address((server_protocol_type)pbReq.protocol, &addr);
306-
if (ret == 0) {
307-
if (addr.addr_type == IP_ADDRESS) {
308-
const unsigned n1 = (addr.ip >> 24) & 0xff,
309-
n2 = (addr.ip >> 16) & 0xff,
310-
n3 = (addr.ip >> 8) & 0xff,
311-
n4 = addr.ip & 0xff;
312-
const int n = snprintf(addr.domain, sizeof(addr.domain), "%u.%u.%u.%u", n1, n2, n3, n4);
313-
if (n > 0 && (size_t)n < sizeof(addr.domain)) {
314-
addr.length = n;
315-
} else {
316-
ret = SYSTEM_ERROR_TOO_LARGE;
317-
}
318-
}
319-
if (ret == 0) {
320-
particle_ctrl_GetServerAddressReply pbRep = {};
321-
EncodedString pbAddr(&pbRep.address, addr.domain, addr.length);
322-
pbRep.port = addr.port;
323-
ret = encodeReplyMessage(req, particle_ctrl_GetServerAddressReply_fields, &pbRep);
324-
}
325-
}
326-
}
327-
return ret;
328-
}
329-
330-
int handleSetServerProtocolRequest(ctrl_request* req) {
331-
particle_ctrl_SetServerProtocolRequest pbReq = {};
332-
int ret = decodeRequestMessage(req, particle_ctrl_SetServerProtocolRequest_fields, &pbReq);
333-
if (ret == 0) {
334-
bool udpEnabled = false;
335-
if (pbReq.protocol == particle_ctrl_ServerProtocolType_TCP_PROTOCOL ||
336-
(udpEnabled = (pbReq.protocol == particle_ctrl_ServerProtocolType_UDP_PROTOCOL))) {
337-
ret = HAL_Feature_Set(FEATURE_CLOUD_UDP, udpEnabled);
338-
} else {
339-
ret = SYSTEM_ERROR_NOT_SUPPORTED;
340-
}
341-
}
342-
return ret;
343-
}
344-
345-
int handleGetServerProtocolRequest(ctrl_request* req) {
346-
particle_ctrl_GetServerProtocolReply pbRep = {};
347-
if (HAL_Feature_Get(FEATURE_CLOUD_UDP)) {
348-
pbRep.protocol = particle_ctrl_ServerProtocolType_UDP_PROTOCOL;
349-
} else {
350-
pbRep.protocol = particle_ctrl_ServerProtocolType_TCP_PROTOCOL;
351-
}
352-
const int ret = encodeReplyMessage(req, particle_ctrl_GetServerProtocolReply_fields, &pbRep);
353-
return ret;
354-
}
355-
356-
int handleSetSoftapSsidRequest(ctrl_request* req) {
357-
particle_ctrl_SetSoftApSsidRequest pbReq = {};
358-
int ret = decodeRequestMessage(req, particle_ctrl_SetSoftApSsidRequest_fields, &pbReq);
359-
if (ret == 0 && (!HAL_Set_System_Config(SYSTEM_CONFIG_SOFTAP_PREFIX, pbReq.prefix, strlen(pbReq.prefix)) ||
360-
!HAL_Set_System_Config(SYSTEM_CONFIG_SOFTAP_SUFFIX, pbReq.suffix, strlen(pbReq.suffix)))) {
361-
ret = SYSTEM_ERROR_UNKNOWN;
362-
}
363-
return ret;
364-
}
365-
366-
#else // HAL_PLATFORM_NRF52840
367241

242+
#if HAL_PLATFORM_NRF52840
368243
// TODO
369244
int handleSetSecurityKeyRequest(ctrl_request*) {
370245
return SYSTEM_ERROR_NOT_SUPPORTED;
@@ -394,7 +269,7 @@ int handleSetSoftapSsidRequest(ctrl_request*) {
394269
return SYSTEM_ERROR_NOT_SUPPORTED;
395270
}
396271

397-
#endif
272+
#endif // HAL_PLATFORM_NRF52840
398273

399274
} // particle::control::config
400275

system/src/control/storage.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,7 @@
2323
#include "system_network.h"
2424
#include "common.h"
2525

26-
#if HAL_PLATFORM_NRF52840
2726
#include "ota_flash_hal_impl.h"
28-
#else
29-
#include "ota_flash_hal_stm32f2xx.h"
30-
#endif
3127

3228
#include "delay_hal.h"
3329

system/src/main.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,10 @@
8989
#include "radio_common.h"
9090
#endif
9191

92-
#if PLATFORM_ID == 3
92+
#if PLATFORM_ID == PLATFORM_GCC
9393
// Application loop uses std::this_thread::sleep_for() to workaround 100% CPU usage on the GCC platform
9494
#include <thread>
95-
#endif
95+
#endif // PLATFORM_ID == PLATFORM_GCC
9696

9797
using namespace spark;
9898
using namespace particle;
@@ -516,15 +516,15 @@ void app_loop(bool threaded)
516516
}
517517
}
518518
} while(false);
519-
#if PLATFORM_ID == 3 && SUSPEND_APPLICATION_THREAD_LOOP_COUNT
519+
#if PLATFORM_ID == PLATFORM_GCC && SUSPEND_APPLICATION_THREAD_LOOP_COUNT
520520
// Suspend thread execution for some minimum time on every Nth loop iteration in order to workaround
521521
// 100% CPU usage on the virtual device platform
522522
static uint32_t loops = 0;
523523
if (++loops >= SUSPEND_APPLICATION_THREAD_LOOP_COUNT) {
524524
loops = 0;
525525
std::this_thread::sleep_for(std::chrono::nanoseconds(1));
526526
}
527-
#endif // PLATFORM_ID == 3
527+
#endif // PLATFORM_ID == PLATFORM_GCC && SUSPEND_APPLICATION_THREAD_LOOP_COUNT
528528
}
529529

530530

system/src/system_network_compat.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
*/
1919

2020
#include "hal_platform.h"
21-
2221
/* FIXME: there should be a define that tells whether there is NetworkManager available
2322
* or not */
2423
#if !HAL_PLATFORM_IFAPI

system/src/system_network_internal.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,10 +196,10 @@ class ManagedNetworkInterface : public NetworkInterface
196196
volatile uint8_t WLAN_DHCP_PENDING = 0;
197197
volatile uint8_t WLAN_LISTEN_ON_FAILED_CONNECT = 0;
198198
volatile uint8_t WLAN_INITIALIZED = 0;
199-
#if PLATFORM_ID == PLATFORM_ELECTRON // Electron
200-
volatile uint32_t START_LISTENING_TIMER_MS = 300000UL; // 5 minute default on Electron
199+
#if HAL_PLATFORM_CELLULAR
200+
volatile uint32_t START_LISTENING_TIMER_MS = 300000UL; // 5 minute default for Cellular devices
201201
#else
202-
volatile uint32_t START_LISTENING_TIMER_MS = 0UL; // Disabled by default on Photon/P1/Core
202+
volatile uint32_t START_LISTENING_TIMER_MS = 0UL; // Disabled for Wi-Fi devices
203203
#endif
204204
volatile uint32_t start_listening_timer_base = 0;
205205
volatile uint32_t start_listening_timer_duration = 0;

system/src/system_sleep.cpp

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,7 @@ network_status_t system_sleep_network_suspend(network_interface_index index) {
7171

7272
// Turn off the modem
7373
if (!network_is_off(index, nullptr)) {
74-
#if PLATFORM_GEN == 2
75-
if (!SPARK_WLAN_SLEEP) {
76-
status.on = true;
77-
}
78-
#endif
79-
#if PLATFORM_GEN == 3
74+
#if HAL_PLATFORM_IFAPI
8075
if_t iface;
8176
if (!if_get_by_index(index, &iface)) {
8277
if (NetworkManager::instance()->isInterfacePowerState(iface, IF_POWER_STATE_UP) ||
@@ -97,25 +92,12 @@ network_status_t system_sleep_network_suspend(network_interface_index index) {
9792
}
9893

9994
int system_sleep_network_resume(network_interface_index index, network_status_t status) {
100-
#if PLATFORM_GEN == 2
101-
/* On Gen2, calling network_on() and network_connect() will block until the connection is established
102-
* if single threaded, or this function is invoked synchronously by the system thread if system threading
103-
* is enabled. In both case, that would block the user application. Setting a flag here to unblock the user
104-
* application and restore the connection later. */
105-
if (status.on) {
106-
SPARK_WLAN_SLEEP = 0;
107-
}
108-
if (status.connected) {
109-
SPARK_WLAN_CONNECT_RESTORE = 1;
110-
}
111-
#else
11295
if (status.on) {
11396
network_on(index, 0, 0, nullptr);
11497
}
11598
if (status.connected) {
11699
network_connect(index, 0, 0, nullptr);
117100
}
118-
#endif
119101
return SYSTEM_ERROR_NONE;
120102
}
121103
#endif // PLATFORM_ID != PLATFORM_GCC
@@ -259,12 +241,5 @@ int system_sleep_ext_impl(const hal_sleep_config_t* config, hal_wakeup_source_ba
259241

260242
int system_sleep_ext(const hal_sleep_config_t* config, hal_wakeup_source_base_t** reason, void* reserved) {
261243
LOG(TRACE, "Entering system_sleep_ext()");
262-
#if HAL_PLATFORM_GEN == 2
263-
// Cancel current connection attempt to unblock the system thread
264-
// on Gen 2 platforms
265-
if (network_connecting(NETWORK_INTERFACE_ALL, 0, nullptr)) {
266-
network_connect_cancel(NETWORK_INTERFACE_ALL, 1, 0, 0);
267-
}
268-
#endif // HAL_PLATFORM_GEN == 2
269244
return system_sleep_ext_impl(config, reason, reserved);
270245
}

system/src/system_sleep_compat.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,6 @@
2929
#include "cellular_hal.h"
3030
#endif // HAL_PLATFORM_CELLULAR
3131
#include "spark_wiring_system.h"
32-
#if PLATFORM_ID == PLATFORM_ELECTRON_PRODUCTION
33-
# include "parser.h"
34-
#endif
3532
#include "system_sleep_configuration.h"
3633
#include "check.h"
3734

@@ -64,6 +61,7 @@ static void network_resume() {
6461
if (wakeupState.wifi) {
6562
SPARK_WLAN_SLEEP = 0;
6663
}
64+
// Outdated - Fix with GCC refactoring
6765
// Gen2-only: Set the system flags that triggers the wifi/cloud reconnection in the background loop
6866
// FIXME: Gen3 won't automatically restore the modem state and network connection if cloud auto-connect flag is not set.
6967
// See manage_network_connection() in system_network_manager_api.cpp.

system/src/system_task.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -303,15 +303,6 @@ void establish_cloud_connection()
303303
return;
304304
}
305305

306-
#if PLATFORM_ID==PLATFORM_ELECTRON_PRODUCTION
307-
const CellularNetProvData provider_data = cellular_network_provider_data_get(NULL);
308-
protocol::connection_properties_t conn_prop = {};
309-
conn_prop.size = sizeof(conn_prop);
310-
conn_prop.keepalive_source = protocol::KeepAliveSource::SYSTEM;
311-
spark_set_connection_property(protocol::Connection::PING, (provider_data.keepalive * 1000), &conn_prop, nullptr);
312-
spark_cloud_udp_port_set(provider_data.port);
313-
#endif // PLATFORM_ID==PLATFORM_ELECTRON_PRODUCTION
314-
315306
INFO("Cloud: connecting");
316307
const auto diag = CloudDiagnostics::instance();
317308
diag->status(CloudDiagnostics::CONNECTING);

0 commit comments

Comments
 (0)