Skip to content

Commit 782141b

Browse files
author
Mika Tervonen
authored
Allowed to set Wi-SUN certificates in DISCONNECTED state (#13071)
Before certificates were able to set only once. Now after disconnect those can be set Again Also those can be set when stack is active
1 parent c0ca645 commit 782141b

File tree

1 file changed

+20
-23
lines changed

1 file changed

+20
-23
lines changed

features/nanostack/mbed-mesh-api/source/wisun_tasklet.c

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -540,44 +540,41 @@ int8_t wisun_tasklet_network_init(int8_t device_id)
540540

541541
int wisun_tasklet_set_own_certificate(uint8_t *cert, uint16_t cert_len, uint8_t *cert_key, uint16_t cert_key_len)
542542
{
543-
if (wisun_tasklet_data_ptr) {
544-
// this API can be only used before first connect()
545-
tr_err("Already connected");
546-
return -2;
547-
}
548-
543+
if (wisun_tasklet_data_ptr && wisun_tasklet_data_ptr->network_interface_id != INVALID_INTERFACE_ID) {
544+
// interface already active write certificates to stack.
545+
arm_certificate_entry_s arm_cert_entry;
546+
arm_cert_entry.cert = cert;
547+
arm_cert_entry.cert_len = cert_len;
548+
arm_cert_entry.key = cert_key;
549+
arm_cert_entry.key_len = cert_key_len;
550+
return arm_network_own_certificate_add(&arm_cert_entry);
551+
}
552+
// Stack is inactive store the certificates and activate when connect() called
549553
return wisun_tasklet_store_certificate_data(cert, cert_len, cert_key, cert_key_len, false, false, false);
550554
}
551555

552556
int wisun_tasklet_remove_own_certificates(void)
553557
{
554-
if (wisun_tasklet_data_ptr) {
555-
// this API can be only used before first connect()
556-
tr_err("Already connected");
557-
return -2;
558-
}
559-
560558
return wisun_tasklet_store_certificate_data(NULL, 0, NULL, 0, true, false, false);
561559
}
562560

563561
int wisun_tasklet_remove_trusted_certificates(void)
564562
{
565-
if (wisun_tasklet_data_ptr) {
566-
// this API can be only used before first connect()
567-
tr_err("Already connected");
568-
return -2;
569-
}
570-
571563
return wisun_tasklet_store_certificate_data(NULL, 0, NULL, 0, false, true, false);
572564
}
573565

574566
int wisun_tasklet_set_trusted_certificate(uint8_t *cert, uint16_t cert_len)
575567
{
576-
if (wisun_tasklet_data_ptr) {
577-
// this API can be only used before first connect()
578-
tr_err("Already connected");
579-
return -2;
580-
}
568+
if (wisun_tasklet_data_ptr && wisun_tasklet_data_ptr->network_interface_id != INVALID_INTERFACE_ID) {
569+
// interface already active write certificates to stack.
570+
arm_certificate_entry_s arm_cert_entry;
571+
arm_cert_entry.cert = cert;
572+
arm_cert_entry.cert_len = cert_len;
573+
arm_cert_entry.key = NULL;
574+
arm_cert_entry.key_len = 0;
575+
return arm_network_trusted_certificate_add(&arm_cert_entry);
576+
}
577+
// Stack is inactive store the certificates and activate when connect() called
581578
return wisun_tasklet_store_certificate_data(cert, cert_len, NULL, 0, false, false, true);
582579
}
583580

0 commit comments

Comments
 (0)