Skip to content

Commit ad6ed89

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 c7759fe commit ad6ed89

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

644644
int wisun_tasklet_set_own_certificate(uint8_t *cert, uint16_t cert_len, uint8_t *cert_key, uint16_t cert_key_len)
645645
{
646-
if (wisun_tasklet_data_ptr) {
647-
// this API can be only used before first connect()
648-
tr_err("Already connected");
649-
return -2;
650-
}
651-
646+
if (wisun_tasklet_data_ptr && wisun_tasklet_data_ptr->network_interface_id != INVALID_INTERFACE_ID) {
647+
// interface already active write certificates to stack.
648+
arm_certificate_entry_s arm_cert_entry;
649+
arm_cert_entry.cert = cert;
650+
arm_cert_entry.cert_len = cert_len;
651+
arm_cert_entry.key = cert_key;
652+
arm_cert_entry.key_len = cert_key_len;
653+
return arm_network_own_certificate_add(&arm_cert_entry);
654+
}
655+
// Stack is inactive store the certificates and activate when connect() called
652656
return wisun_tasklet_store_certificate_data(cert, cert_len, cert_key, cert_key_len, false, false, false);
653657
}
654658

655659
int wisun_tasklet_remove_own_certificates(void)
656660
{
657-
if (wisun_tasklet_data_ptr) {
658-
// this API can be only used before first connect()
659-
tr_err("Already connected");
660-
return -2;
661-
}
662-
663661
return wisun_tasklet_store_certificate_data(NULL, 0, NULL, 0, true, false, false);
664662
}
665663

666664
int wisun_tasklet_remove_trusted_certificates(void)
667665
{
668-
if (wisun_tasklet_data_ptr) {
669-
// this API can be only used before first connect()
670-
tr_err("Already connected");
671-
return -2;
672-
}
673-
674666
return wisun_tasklet_store_certificate_data(NULL, 0, NULL, 0, false, true, false);
675667
}
676668

677669
int wisun_tasklet_set_trusted_certificate(uint8_t *cert, uint16_t cert_len)
678670
{
679-
if (wisun_tasklet_data_ptr) {
680-
// this API can be only used before first connect()
681-
tr_err("Already connected");
682-
return -2;
683-
}
671+
if (wisun_tasklet_data_ptr && wisun_tasklet_data_ptr->network_interface_id != INVALID_INTERFACE_ID) {
672+
// interface already active write certificates to stack.
673+
arm_certificate_entry_s arm_cert_entry;
674+
arm_cert_entry.cert = cert;
675+
arm_cert_entry.cert_len = cert_len;
676+
arm_cert_entry.key = NULL;
677+
arm_cert_entry.key_len = 0;
678+
return arm_network_trusted_certificate_add(&arm_cert_entry);
679+
}
680+
// Stack is inactive store the certificates and activate when connect() called
684681
return wisun_tasklet_store_certificate_data(cert, cert_len, NULL, 0, false, false, true);
685682
}

0 commit comments

Comments
 (0)