Skip to content

Commit 1c45286

Browse files
author
Mika Leppänen
committed
Fixed defects and coding style
1 parent 553fbb1 commit 1c45286

File tree

10 files changed

+62
-60
lines changed

10 files changed

+62
-60
lines changed

source/6LoWPAN/ws/ws_pae_controller.c

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ typedef struct {
7575
ws_pae_nw_key_index_update *pae_nw_key_index_update; /**< PAE NW key index update */
7676
bool gtks_set : 1; /**< GTKs are set */
7777
bool gtkhash_set : 1; /**< GTK hashes are set */
78-
bool key_index_set :1; /**< NW key index is set */
79-
bool nw_keys_init_done :1; /**< NW key initialization has been done */
78+
bool key_index_set : 1; /**< NW key index is set */
79+
bool nw_keys_init_done : 1; /**< NW key initialization has been done */
8080
} pae_controller_t;
8181

8282
static pae_controller_t *ws_pae_controller_get(protocol_interface_info_entry_t *interface_ptr);
@@ -88,9 +88,11 @@ static int8_t ws_pae_controller_free_slot_find(nw_key_t *nw_key);
8888
static NS_LIST_DEFINE(pae_controller_list, pae_controller_t, link);
8989

9090
static sec_prot_gtk_keys_t gtks_storage;
91+
#ifdef HAVE_PAE_AUTH
9192
static int8_t gtk_index = -1;
93+
#endif
9294

93-
#if !defined(HAVE_PAE_SUPP) && !defined(HAVE_PAE_SUPP)
95+
#if !defined(HAVE_PAE_SUPP) && !defined(HAVE_PAE_AUTH)
9496

9597
static void ws_pae_controller_test_keys_set(sec_prot_gtk_keys_t *gtks)
9698
{
@@ -356,12 +358,12 @@ static int8_t ws_pae_controller_free_slot_find(nw_key_t *nw_key)
356358
for (uint8_t slot = NW_KEY_SLOT_FIRST; slot <= NW_KEY_SLOT_LAST; slot++) {
357359
bool slot_used = false;
358360
for (uint8_t i = 0; i < GTK_NUM; i++) {
359-
if (nw_key[i].slot == slot) {
360-
slot_used = true;
361-
}
361+
if (nw_key[i].slot == slot) {
362+
slot_used = true;
363+
}
362364
}
363365
if (!slot_used) {
364-
return slot;
366+
return slot;
365367
}
366368
}
367369

@@ -387,7 +389,7 @@ int8_t ws_pae_controller_init(protocol_interface_info_entry_t *interface_ptr)
387389
memset(controller->br_eui_64, 0, 8);
388390
memset(controller->gtkhash, 0, 32);
389391
memset(controller->nw_key, 0, sizeof(controller->nw_key));
390-
controller->target_pan_id = 0;
392+
controller->target_pan_id = 0xffff;
391393
controller->interface_ptr = interface_ptr;
392394
controller->auth_completed = NULL;
393395
controller->nw_key_insert = NULL;
@@ -596,6 +598,7 @@ int8_t ws_pae_controller_gtk_update(int8_t interface_id, uint8_t *gtk[4])
596598

597599
int8_t ws_pae_controller_active_key_update(int8_t interface_id, uint8_t index)
598600
{
601+
#ifdef HAVE_PAE_AUTH
599602
protocol_interface_info_entry_t *cur = protocol_stack_interface_info_get_by_id(interface_id);
600603

601604
pae_controller_t *controller = ws_pae_controller_get(cur);
@@ -606,6 +609,11 @@ int8_t ws_pae_controller_active_key_update(int8_t interface_id, uint8_t index)
606609
}
607610

608611
return 0;
612+
#else
613+
(void) interface_id;
614+
(void) index;
615+
return -1;
616+
#endif
609617
}
610618

611619
static void ws_pae_controller_gtk_hash_set(protocol_interface_info_entry_t *interface_ptr, uint8_t *gtkhash)

source/6LoWPAN/ws/ws_pae_supp.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ typedef struct {
101101
static trickle_params_t auth_trickle_params = {
102102
.Imin = TRICKLE_IMIN_120_SECS, /* 120 second; ticks are 100ms */
103103
.Imax = TRICKLE_IMIN_120_SECS << 1, /* 240 second */
104-
.k = 0, /* infinity - no consistency checking */
104+
.k = 0, /* infinity - no consistency checking */
105105
.TimerExpirations = 3
106106
};
107107

source/Security/kmp/kmp_api.c

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -37,24 +37,24 @@
3737
#define TRACE_GROUP "kmap"
3838

3939
struct kmp_api_s {
40-
void *app_data_ptr; /**< Opaque pointer for application data */
41-
kmp_api_create_confirm *create_conf; /**< KMP-CREATE.confirm callback */
42-
kmp_api_create_indication *create_ind; /**< KMP-CREATE.indication callback */
43-
kmp_api_finished_indication *finished_ind; /**< KMP-FINISHED.indication callback */
44-
kmp_api_finished *finished; /**< Finished i.e. ready to be deleted callback */
45-
kmp_type_e type; /**< KMP type */
46-
kmp_addr_t *addr; /**< Supplicant EUI-64, Relay IP address, Relay port */
47-
kmp_service_t *service; /**< KMP service */
48-
bool timer_start_pending :1; /**< Timer is pending to start */
49-
bool receive_disable :1; /**< Receiving disabled, do not route messages anymore */
50-
sec_prot_t sec_prot; /**< Security protocol interface */
40+
void *app_data_ptr; /**< Opaque pointer for application data */
41+
kmp_api_create_confirm *create_conf; /**< KMP-CREATE.confirm callback */
42+
kmp_api_create_indication *create_ind; /**< KMP-CREATE.indication callback */
43+
kmp_api_finished_indication *finished_ind; /**< KMP-FINISHED.indication callback */
44+
kmp_api_finished *finished; /**< Finished i.e. ready to be deleted callback */
45+
kmp_type_e type; /**< KMP type */
46+
kmp_addr_t *addr; /**< Supplicant EUI-64, Relay IP address, Relay port */
47+
kmp_service_t *service; /**< KMP service */
48+
bool timer_start_pending : 1; /**< Timer is pending to start */
49+
bool receive_disable : 1; /**< Receiving disabled, do not route messages anymore */
50+
sec_prot_t sec_prot; /**< Security protocol interface */
5151
};
5252

5353
typedef struct {
54-
kmp_type_e type; /**< Security protocol type callback */
55-
kmp_sec_prot_size *size; /**< Security protocol data size callback */
56-
kmp_sec_prot_init *init; /**< Security protocol init */
57-
ns_list_link_t link; /**< Link */
54+
kmp_type_e type; /**< Security protocol type callback */
55+
kmp_sec_prot_size *size; /**< Security protocol data size callback */
56+
kmp_sec_prot_init *init; /**< Security protocol init */
57+
ns_list_link_t link; /**< Link */
5858
} kmp_sec_prot_entry_t;
5959

6060
typedef NS_LIST_HEAD(kmp_sec_prot_entry_t, link) kmp_sec_prot_list_t;

source/Security/protocols/eap_tls_sec_prot/auth_eap_tls_sec_prot.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,8 @@ static int8_t auth_eap_tls_sec_prot_message_handle(sec_prot_t *prot)
195195
}
196196

197197
tr_info("EAP-TLS: recv %s type %s id %i flags %x len %i, eui-64 %s", eap_msg_trace[data->eap_code - 1],
198-
data->eap_type == EAP_IDENTITY ? "IDENTITY" : "TLS", data->recv_eapol_pdu.msg.eap.id_seq,
199-
length >= 6 ? data_ptr[0] : 0, length, trace_array(sec_prot_remote_eui_64_addr_get(prot), 8));
198+
data->eap_type == EAP_IDENTITY ? "IDENTITY" : "TLS", data->recv_eapol_pdu.msg.eap.id_seq,
199+
length >= 6 ? data_ptr[0] : 0, length, trace_array(sec_prot_remote_eui_64_addr_get(prot), 8));
200200

201201
if (data->eap_type == EAP_IDENTITY) {
202202
return EAP_TLS_MSG_IDENTITY;
@@ -238,8 +238,8 @@ static int8_t auth_eap_tls_sec_prot_message_send(sec_prot_t *prot, uint8_t eap_c
238238
}
239239

240240
tr_info("EAP-TLS: send %s type %s id %i flags %x len %i, eui-64: %s", eap_msg_trace[eap_code - 1],
241-
eap_type == EAP_IDENTITY ? "IDENTITY" : "TLS", data->eap_id_seq, flags, eapol_pdu_size,
242-
trace_array(sec_prot_remote_eui_64_addr_get(prot), 8));
241+
eap_type == EAP_IDENTITY ? "IDENTITY" : "TLS", data->eap_id_seq, flags, eapol_pdu_size,
242+
trace_array(sec_prot_remote_eui_64_addr_get(prot), 8));
243243

244244
if (prot->send(prot, eapol_decoded_data, eapol_pdu_size + prot->header_size) < 0) {
245245
return -1;

source/Security/protocols/eap_tls_sec_prot/supp_eap_tls_sec_prot.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,8 @@ static int8_t supp_eap_tls_sec_prot_message_handle(sec_prot_t *prot)
192192
}
193193

194194
tr_info("EAP-TLS recv %s type %s id %i flags %x len %i", eap_msg_trace[data->eap_code - 1],
195-
data->eap_type == EAP_IDENTITY ? "IDENTITY" : "TLS", data->recv_eapol_pdu.msg.eap.id_seq,
196-
length >= 6 ? data_ptr[0] : 0, length);
195+
data->eap_type == EAP_IDENTITY ? "IDENTITY" : "TLS", data->recv_eapol_pdu.msg.eap.id_seq,
196+
length >= 6 ? data_ptr[0] : 0, length);
197197

198198
if (data->eap_type == EAP_IDENTITY) {
199199
return EAP_TLS_MSG_IDENTITY;
@@ -239,7 +239,7 @@ static int8_t supp_eap_tls_sec_prot_message_send(sec_prot_t *prot, uint8_t eap_c
239239
}
240240

241241
tr_info("EAP-TLS: send %s type %s id %i flags %x len %i", eap_msg_trace[eap_code - 1],
242-
eap_type == EAP_IDENTITY ? "IDENTITY" : "TLS", data->eap_id_seq, flags, eapol_pdu_size);
242+
eap_type == EAP_IDENTITY ? "IDENTITY" : "TLS", data->eap_id_seq, flags, eapol_pdu_size);
243243

244244
if (prot->send(prot, eapol_decoded_data, eapol_pdu_size + prot->header_size) < 0) {
245245
return -1;

source/Security/protocols/fwh_sec_prot/supp_fwh_sec_prot.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ typedef struct {
7777
void *recv_pdu; /**< received pdu */
7878
uint16_t recv_size; /**< received pdu size */
7979
uint64_t recv_replay_cnt; /**< received replay counter */
80-
bool msg3_retry_wait :1; /**< Waiting for Message 3 retry */
80+
bool msg3_retry_wait : 1; /**< Waiting for Message 3 retry */
8181
} fwh_sec_prot_int_t;
8282

8383
static uint16_t supp_fwh_sec_prot_size(void);

source/Security/protocols/key_sec_prot/key_sec_prot.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -206,25 +206,26 @@ static int8_t key_sec_prot_receive(sec_prot_t *prot, void *pdu, uint16_t size)
206206
return -1;
207207
}
208208

209-
// Checks if supplicant indicates that it has valid PMK
209+
// Default assumption is that PMK and PTK are not valid
210210
prot->sec_keys->pmk_mismatch = true;
211-
uint8_t remote_pmkid[PMKID_LEN];
212-
if (kde_pmkid_read(kde, kde_len, remote_pmkid) >= 0) {
211+
prot->sec_keys->ptk_mismatch = true;
212+
213+
// Checks if supplicant indicates that it has valid PMK
214+
uint8_t remote_keyid[KEYID_LEN];
215+
if (kde_pmkid_read(kde, kde_len, remote_keyid) >= 0) {
213216
uint8_t pmkid[PMKID_LEN];
214217
if (sec_prot_lib_pmkid_generate(prot, pmkid, true) >= 0) {
215-
if (memcmp(remote_pmkid, pmkid, PMKID_LEN) == 0) {
218+
if (memcmp(remote_keyid, pmkid, PMKID_LEN) == 0) {
216219
prot->sec_keys->pmk_mismatch = false;
217220
}
218221
}
219222
}
220223

221224
// Checks if supplicant indicates that it has valid PTK
222-
prot->sec_keys->ptk_mismatch = true;
223-
uint8_t remote_ptkid[PTKID_LEN];
224-
if (kde_ptkid_read(kde, kde_len, remote_ptkid) >= 0) {
225+
if (kde_ptkid_read(kde, kde_len, remote_keyid) >= 0) {
225226
uint8_t ptkid[PTKID_LEN];
226227
if (sec_prot_lib_ptkid_generate(prot, ptkid, true) >= 0) {
227-
if (memcmp(remote_ptkid, ptkid, PTKID_LEN) == 0) {
228+
if (memcmp(remote_keyid, ptkid, PTKID_LEN) == 0) {
228229
prot->sec_keys->ptk_mismatch = false;
229230
}
230231
}

source/Security/protocols/sec_prot_keys.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -204,9 +204,9 @@ uint8_t sec_prot_keys_fresh_gtkl_get(sec_prot_gtk_keys_t *gtks)
204204
uint8_t gtkl = 0;
205205

206206
for (uint8_t i = 0; i < GTK_NUM; i++) {
207-
if (sec_prot_keys_gtk_status_is_live(gtks, i)) {
208-
gtkl |= 1 << i;
209-
}
207+
if (sec_prot_keys_gtk_status_is_live(gtks, i)) {
208+
gtkl |= 1 << i;
209+
}
210210
}
211211

212212
return gtkl;
@@ -282,13 +282,13 @@ int8_t sec_prot_keys_gtk_insert_index_from_gtkl_get(sec_prot_keys_t *sec_keys)
282282

283283
// Checks all keys
284284
for (uint8_t i = 0; i < GTK_NUM; i++) {
285-
if (sec_prot_keys_gtk_status_is_live(sec_keys->gtks, i)) {
286-
// If key is live, but not indicated on GTKL inserts it
287-
if (!sec_prot_keys_gtkl_gtk_is_live(sec_keys, i)) {
288-
sec_prot_keys_gtk_insert_index_set(sec_keys, i);
289-
return i;
290-
}
291-
}
285+
if (sec_prot_keys_gtk_status_is_live(sec_keys->gtks, i)) {
286+
// If key is live, but not indicated on GTKL inserts it
287+
if (!sec_prot_keys_gtkl_gtk_is_live(sec_keys, i)) {
288+
sec_prot_keys_gtk_insert_index_set(sec_keys, i);
289+
return i;
290+
}
291+
}
292292
}
293293

294294
return -1;

source/Security/protocols/sec_prot_keys.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939

4040
#define PMKID_LEN 16
4141
#define PTKID_LEN 16
42+
#define KEYID_LEN 16
4243

4344
#define GTK_DEFAULT_LIFETIME 60 * 60 * 24 * 30 // 30 days
4445

source/Security/protocols/sec_prot_lib.c

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -477,15 +477,11 @@ int8_t sec_prot_lib_pmkid_generate(sec_prot_t *prot, uint8_t *pmkid, bool is_aut
477477
prot->addr_get(prot, local_eui64, remote_eui64);
478478
}
479479

480-
int8_t ret;
481-
482480
if (is_auth) {
483-
ret = sec_prot_lib_pmkid_calc(pmk, local_eui64, remote_eui64, pmkid);
481+
return sec_prot_lib_pmkid_calc(pmk, local_eui64, remote_eui64, pmkid);
484482
} else {
485-
ret = sec_prot_lib_pmkid_calc(pmk, remote_eui64, local_eui64, pmkid);
483+
return sec_prot_lib_pmkid_calc(pmk, remote_eui64, local_eui64, pmkid);
486484
}
487-
488-
return ret;
489485
}
490486

491487
int8_t sec_prot_lib_ptkid_generate(sec_prot_t *prot, uint8_t *ptkid, bool is_auth)
@@ -502,15 +498,11 @@ int8_t sec_prot_lib_ptkid_generate(sec_prot_t *prot, uint8_t *ptkid, bool is_aut
502498
return -1;
503499
}
504500

505-
int8_t ret;
506-
507501
if (is_auth) {
508502
return sec_prot_lib_ptkid_calc(ptk, local_eui64, remote_eui64, ptkid);
509503
} else {
510504
return sec_prot_lib_ptkid_calc(ptk, remote_eui64, local_eui64, ptkid);
511505
}
512-
513-
return ret;
514506
}
515507

516508
int8_t sec_prot_lib_gtkhash_generate(uint8_t *gtk, uint8_t *gtk_hash)

0 commit comments

Comments
 (0)