Skip to content

Commit bd00cf1

Browse files
author
Mika Tervonen
committed
Allowed to set Wi-SUN certificates in DISCONNECTED state
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 f7861e6 commit bd00cf1

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
@@ -637,43 +637,40 @@ int wisun_tasklet_set_regulatory_domain(int8_t nwk_interface_id, uint8_t regulat
637637

638638
int wisun_tasklet_set_own_certificate(uint8_t *cert, uint16_t cert_len, uint8_t *cert_key, uint16_t cert_key_len)
639639
{
640-
if (wisun_tasklet_data_ptr) {
641-
// this API can be only used before first connect()
642-
tr_err("Already connected");
643-
return -2;
644-
}
645-
640+
if (wisun_tasklet_data_ptr && wisun_tasklet_data_ptr->network_interface_id != INVALID_INTERFACE_ID) {
641+
// interface already active write certificates to stack.
642+
arm_certificate_entry_s arm_cert_entry;
643+
arm_cert_entry.cert = cert;
644+
arm_cert_entry.cert_len = cert_len;
645+
arm_cert_entry.key = cert_key;
646+
arm_cert_entry.key_len = cert_key_len;
647+
return arm_network_own_certificate_add(&arm_cert_entry);
648+
}
649+
// Stack is inactive store the certificates and activate when connect() called
646650
return wisun_tasklet_store_certificate_data(cert, cert_len, cert_key, cert_key_len, false, false, false);
647651
}
648652

649653
int wisun_tasklet_remove_own_certificates(void)
650654
{
651-
if (wisun_tasklet_data_ptr) {
652-
// this API can be only used before first connect()
653-
tr_err("Already connected");
654-
return -2;
655-
}
656-
657655
return wisun_tasklet_store_certificate_data(NULL, 0, NULL, 0, true, false, false);
658656
}
659657

660658
int wisun_tasklet_remove_trusted_certificates(void)
661659
{
662-
if (wisun_tasklet_data_ptr) {
663-
// this API can be only used before first connect()
664-
tr_err("Already connected");
665-
return -2;
666-
}
667-
668660
return wisun_tasklet_store_certificate_data(NULL, 0, NULL, 0, false, true, false);
669661
}
670662

671663
int wisun_tasklet_set_trusted_certificate(uint8_t *cert, uint16_t cert_len)
672664
{
673-
if (wisun_tasklet_data_ptr) {
674-
// this API can be only used before first connect()
675-
tr_err("Already connected");
676-
return -2;
677-
}
665+
if (wisun_tasklet_data_ptr && wisun_tasklet_data_ptr->network_interface_id != INVALID_INTERFACE_ID) {
666+
// interface already active write certificates to stack.
667+
arm_certificate_entry_s arm_cert_entry;
668+
arm_cert_entry.cert = cert;
669+
arm_cert_entry.cert_len = cert_len;
670+
arm_cert_entry.key = NULL;
671+
arm_cert_entry.key_len = 0;
672+
return arm_network_trusted_certificate_add(&arm_cert_entry);
673+
}
674+
// Stack is inactive store the certificates and activate when connect() called
678675
return wisun_tasklet_store_certificate_data(cert, cert_len, NULL, 0, false, false, true);
679676
}

0 commit comments

Comments
 (0)