Skip to content

Commit 0515ed1

Browse files
authored
Merge pull request #13072 from mikter/ws_certificate_set_change_5.15
[mbed-os-5.15] Allowed to set Wi-SUN certificates in DISCONNECTED state
2 parents 82e2f90 + bd00cf1 commit 0515ed1

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
@@ -541,44 +541,41 @@ int8_t wisun_tasklet_network_init(int8_t device_id)
541541

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

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

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

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

0 commit comments

Comments
 (0)