/*---------------------------------------------------------------------------*/ static void send_broadcast(mac_callback_t sent, void *ptr) { struct queuebuf *qb; qb = queuebuf_new_from_packetbuf(); if(!qb || (NETSTACK_FRAMER.create() < 0)) { PRINTF("coresec-strategy: Did not send broadcast\n"); if(qb) { queuebuf_free(qb); } sent(ptr, MAC_TX_ERR, 0); return; } prepare_announce(); adaptivesec_send_command_frame(); watchdog_periodic(); queuebuf_to_packetbuf(qb); queuebuf_free(qb); #if WITH_BROADCAST_ENCRYPTION { uint8_t ignore[ADAPTIVESEC_BROADCAST_MIC_LEN]; if(packetbuf_attr(PACKETBUF_ATTR_SECURITY_LEVEL) & (1 << 2)) { adaptivesec_aead(adaptivesec_group_key, 1, ignore, 1); } } #endif /* WITH_BROADCAST_ENCRYPTION */ NETSTACK_MAC.send(sent, ptr); }
/*---------------------------------------------------------------------------*/ static void send_helloack(void *ptr) { struct akes_nbr_entry *entry; uint8_t challenges[2 * AKES_NBR_CHALLENGE_LEN]; uint8_t *secret; PRINTF("akes: Sending HELLOACK\n"); entry = (struct akes_nbr_entry *)ptr; akes_nbr_copy_challenge(challenges, entry->tentative->challenge); csprng_rand(challenges + AKES_NBR_CHALLENGE_LEN, AKES_NBR_CHALLENGE_LEN); akes_nbr_copy_challenge(entry->tentative->challenge, challenges + AKES_NBR_CHALLENGE_LEN); /* write payload */ prepare_update_command(entry->permanent ? AKES_HELLOACK_P_IDENTIFIER : AKES_HELLOACK_IDENTIFIER, entry, AKES_NBR_TENTATIVE); /* generate pairwise key */ secret = AKES_SCHEME.get_secret_with_hello_sender(akes_nbr_get_addr(entry)); if(!secret) { PRINTF("akes: No secret with HELLO sender\n"); return; } generate_pairwise_key(challenges, secret); akes_nbr_copy_key(entry->tentative->tentative_pairwise_key, challenges); adaptivesec_send_command_frame(); }
/*---------------------------------------------------------------------------*/ static void send_broadcast(mac_callback_t sent, void *ptr) { struct queuebuf *qb; #if ANTI_REPLAY_WITH_SUPPRESSION uint16_t frame_counter_bytes_0_1; uint16_t frame_counter_bytes_2_3; uint8_t seqno; frame_counter_bytes_0_1 = packetbuf_attr(PACKETBUF_ATTR_FRAME_COUNTER_BYTES_0_1); frame_counter_bytes_2_3 = packetbuf_attr(PACKETBUF_ATTR_FRAME_COUNTER_BYTES_2_3); seqno = packetbuf_attr(PACKETBUF_ATTR_MAC_SEQNO); adaptivesec_add_security_header(NULL); #endif /* ANTI_REPLAY_WITH_SUPPRESSION */ qb = queuebuf_new_from_packetbuf(); if(!qb || (NETSTACK_FRAMER.create() < 0)) { PRINTF("coresec-strategy: Did not send broadcast\n"); if(qb) { queuebuf_free(qb); } sent(ptr, MAC_TX_ERR, 0); return; } prepare_announce(); #if ANTI_REPLAY_WITH_SUPPRESSION packetbuf_set_attr(PACKETBUF_ATTR_FRAME_COUNTER_BYTES_0_1, frame_counter_bytes_0_1); packetbuf_set_attr(PACKETBUF_ATTR_FRAME_COUNTER_BYTES_2_3, frame_counter_bytes_2_3); packetbuf_set_attr(PACKETBUF_ATTR_MAC_SEQNO, seqno); #endif /* ANTI_REPLAY_WITH_SUPPRESSION */ adaptivesec_send_command_frame(); watchdog_periodic(); queuebuf_to_packetbuf(qb); queuebuf_free(qb); #if WITH_BROADCAST_ENCRYPTION { uint8_t ignore[ADAPTIVESEC_BROADCAST_MIC_LEN]; if(adaptivesec_get_sec_lvl() & (1 << 2)) { adaptivesec_aead(adaptivesec_group_key, 1, ignore, 1); } } #endif /* WITH_BROADCAST_ENCRYPTION */ NETSTACK_MAC.send(sent, ptr); }