Пример #1
0
static void libdhcpv6_address_generate(dhcpv6_gua_server_entry_s *serverInfo, dhcpv6_alloacted_address_entry_t *entry)
{
    //GENERATE ADDRESS
    uint8_t *ptr = entry->nonTemporalAddress;
    memcpy(ptr, serverInfo->guaPrefix, 8);
    ptr += 8;
    if (serverInfo->enableAddressAutonous) {
        if (entry->linkType == DHCPV6_DUID_HARDWARE_EUI64_TYPE) {
            memcpy(ptr, entry->linkId, 8);
            *ptr ^= 2;
        } else if (entry->linkType == DHCPV6_DUID_HARDWARE_EUI64_TYPE) {
            *ptr++  = entry->linkId[0] ^ 2;
            *ptr++  = entry->linkId[1];
            *ptr++  = entry->linkId[2];
            *ptr++  = 0xff;
            *ptr++  = 0xfe;
            *ptr++  = entry->linkId[3];
            *ptr++  = entry->linkId[4];
            *ptr    = entry->linkId[5];
        } else {
            ptr = common_write_32_bit((serverInfo->clientIdDefaultSuffics | 02000000), ptr);
            ptr = common_write_32_bit((serverInfo->clientIdSequence + 2), ptr);
        }

    } else {
        ptr = common_write_32_bit((serverInfo->clientIdDefaultSuffics | 02000000), ptr);
        ptr = common_write_32_bit((serverInfo->clientIdSequence + 2), ptr);
    }
    serverInfo->clientIdSequence++;
}
Пример #2
0
uint8_t *pana_header_write(uint8_t *ptr, const pana_header_t *header)
{
    ptr = common_write_16_bit(PANA_HEADER_START, ptr);
    ptr = common_write_16_bit(header->payload_len, ptr);
    ptr = common_write_16_bit(header->flags, ptr);
    ptr = common_write_16_bit(header->type, ptr);
    ptr = common_write_32_bit(header->session_id, ptr);
    return common_write_32_bit(header->seq, ptr);
}
Пример #3
0
static int8_t rf_device_register(void)
{
    if (rf_radio_driver_id < 0) {
        rf_mac_hw_init();
        /**
         * Read factory stored Mac address to RAM
         */
        common_write_32_bit(ZLL->MACLONGADDRS0_MSB, MAC64_addr);
        common_write_32_bit(ZLL->MACLONGADDRS0_LSB, MAC64_addr + 4);

        rf_radio_driver_id = arm_net_phy_register(&device_driver);
    }

    return rf_radio_driver_id;
}
Пример #4
0
uint8_t *mle_tlv_write_framecounter(uint8_t *ptr, uint32_t frameCount)
{
    *ptr++ = MLE_TYPE_MLE_FRAME_COUNTER;
    *ptr++ = 4;
    ptr = common_write_32_bit(frameCount, ptr);
    return ptr;
}
Пример #5
0
uint8_t *mle_tlv_write_timeout(uint8_t *ptr, uint32_t timeOut)
{
    *ptr++ = MLE_TYPE_TIMEOUT;
    *ptr++ = 4;
    ptr = common_write_32_bit(timeOut, ptr);
    return ptr;
}
Пример #6
0
static void thread_discover_key_descriptor_set(struct mac_api_s *api, const uint8_t *key, uint8_t id, uint32_t key32_bit_src, uint8_t attribute_index)
{
    mlme_set_t set_req;
    mlme_key_id_lookup_descriptor_t lookup_description;
    mlme_key_descriptor_entry_t key_description;
    mlme_key_device_descriptor_t dev_descriptor;
    if (key) {
        memset(lookup_description.LookupData, 0, 9);
        common_write_32_bit(key32_bit_src, lookup_description.LookupData);
        lookup_description.LookupData[4] = id;
        lookup_description.LookupDataSize = 0;
        memset(&key_description, 0, sizeof(mlme_key_descriptor_entry_t));
        memcpy(key_description.Key, key, 16);
        key_description.KeyIdLookupList = &lookup_description;
        key_description.KeyIdLookupListEntries = 1;
        dev_descriptor.Blacklisted = false;
        dev_descriptor.DeviceDescriptorHandle = attribute_index;
        dev_descriptor.UniqueDevice = true;
        key_description.KeyDeviceList = &dev_descriptor;
        key_description.KeyDeviceListEntries = 1;

    } else {
        memset(&key_description, 0, sizeof(mlme_key_descriptor_entry_t));
    }
    set_req.attr = macKeyTable;
    set_req.attr_index = 3; //Allwayd firth key
    set_req.value_pointer = &key_description;
    set_req.value_size = sizeof(mlme_key_descriptor_entry_t);

    api->mlme_req(api, MLME_SET, &set_req);
}
Пример #7
0
uint8_t *thread_meshcop_tlv_data_write_uint32(uint8_t *ptr, uint8_t type, uint32_t data)
{
    *ptr++ = type;
    *ptr++ = 4;
    ptr = common_write_32_bit(data, ptr);
    return ptr;
}
Пример #8
0
/**
 * Calculate New Key Material by given security key material and sequency number
 *
 * \param key Thread Master key pointer
 * \param key_material_buf Buffer for calculated MAC & MLE key: first 128-bit for MLE and rest 128-bit for MAC
 * \param threadSequency Key material key index.
 *
 */
void thread_key_get(uint8_t *key, uint8_t *key_material_buf,  uint32_t key_sequence_counter)
{
    static uint8_t key_seed[6] = {'T', 'h', 'r', 'e', 'a', 'd'};
    static uint8_t temp32_buf[4];
    common_write_32_bit(key_sequence_counter, temp32_buf);
    SHALIB_init_HMAC(key, 16);
    SHALIB_push_data_HMAC(temp32_buf, 4);
    SHALIB_push_data_HMAC(key_seed, 6);
    SHALIB_finish_HMAC(key_material_buf, 8);
}
Пример #9
0
int8_t pana_ccm_data_crypt(uint8_t *ptr, uint16_t len, uint8_t operation_type, uint32_t message_seq, sec_suite_t *suite)
{
    uint8_t *explict_ptr;
    uint8_t *key_ptr = 0;
    ccm_globals_t ccm_ptr;
    key_ptr = suite->pana_session.pana_PAA_enc_key;

    //Here Comes AES Decrypt
    if (!ccm_sec_init(&ccm_ptr, AES_SECURITY_LEVEL_ENC, key_ptr, operation_type, 3)) {
        return -1;
    }

    explict_ptr = ccm_ptr.exp_nonce;
    //Set IV
    explict_ptr = common_write_32_bit(suite->pana_session.pana_key_id, explict_ptr);
    //SET EXP 4 octest Session ID, 4 Octet Pana SQN number
    explict_ptr = common_write_32_bit(suite->pana_session.session_id, explict_ptr);
    explict_ptr = common_write_32_bit(message_seq, explict_ptr);
    ccm_ptr.data_len = len;
    ccm_ptr.data_ptr  = ptr;
    return ccm_process_run(&ccm_ptr);
}
Пример #10
0
uint8_t* fhss_beacon_encode_raw(uint8_t* buffer, const fhss_synchronization_beacon_payload_s* source)
{
    *buffer++ = FHSS_DATA_START_DELIMETER;
    *buffer++ = source->channel_index;
    *buffer++ = source->sender_unicast_channel;
    buffer = common_write_16_bit(source->current_superframe, buffer);
    buffer = common_write_16_bit(source->remaining_slots, buffer);
    buffer = common_write_16_bit(source->channel_list_counter, buffer);
    *buffer++ = source->hop_count;
    *buffer++ = source->number_of_broadcast_channels;
    *buffer++ = source->number_of_tx_slots;
    buffer = common_write_32_bit(source->time_since_last_beacon, buffer);
    buffer = common_write_16_bit(source->processing_delay, buffer);
    buffer = common_write_16_bit(source->superframe_length, buffer);
    *buffer++ = source->number_of_superframes_per_channel;

    return buffer;
}