コード例 #1
0
ファイル: at86rf231_rx.c プロジェクト: AntonisVafeas/RIOT
void at86rf231_rx_handler(void)
{
    uint8_t lqi, fcs_rssi;
    // read packet length
    at86rf231_read_fifo(&at86rf231_rx_buffer[rx_buffer_next].length, 1);

    // read psdu, read packet with length as first byte and lqi as last byte.
    uint8_t *buf = buffer[rx_buffer_next];
    at86rf231_read_fifo(buf, at86rf231_rx_buffer[rx_buffer_next].length);

    // read lqi which is appended after the psdu
    lqi = buf[at86rf231_rx_buffer[rx_buffer_next].length - 1];

    // read fcs and rssi, from a register
    fcs_rssi = at86rf231_reg_read(AT86RF231_REG__PHY_RSSI);

    // build package
    at86rf231_rx_buffer[rx_buffer_next].lqi = lqi;
    // RSSI has no meaning here, it should be read during packet reception.
    at86rf231_rx_buffer[rx_buffer_next].rssi = fcs_rssi & 0x0F;  // bit[4:0]
    // bit7, boolean, 1 FCS valid, 0 FCS not valid
    at86rf231_rx_buffer[rx_buffer_next].crc = (fcs_rssi >> 7) & 0x01;

    if (at86rf231_rx_buffer[rx_buffer_next].crc == 0) {
        DEBUG("Got packet with invalid crc.\n");
        return;
    }

    ieee802154_frame_read(&buf[1], &at86rf231_rx_buffer[rx_buffer_next].frame,
                          at86rf231_rx_buffer[rx_buffer_next].length);

    if (at86rf231_rx_buffer[rx_buffer_next].frame.fcf.frame_type != 2) {
#if DEBUG_ENABLED
        ieee802154_frame_print_fcf_frame(&at86rf231_rx_buffer[rx_buffer_next].frame);
#endif

        /* notify transceiver thread if any */
        if (transceiver_pid) {
            msg_t m;
            m.type = (uint16_t) RCV_PKT_AT86RF231;
            m.content.value = rx_buffer_next;
            msg_send_int(&m, transceiver_pid);
        }
    }
    else {
#if DEBUG_ENABLED
        DEBUG("GOT ACK for SEQ %u\n", at86rf231_rx_buffer[rx_buffer_next].frame.seq_nr);
        ieee802154_frame_print_fcf_frame(&at86rf231_rx_buffer[rx_buffer_next].frame);
#endif
    }

    // shift to next buffer element
    if (++rx_buffer_next == AT86RF231_RX_BUF_SIZE) {
        rx_buffer_next = 0;
    }

    // Read IRQ to clear it
    at86rf231_reg_read(AT86RF231_REG__IRQ_STATUS);
}
コード例 #2
0
ファイル: at86rf231_rx.c プロジェクト: gavwang/RIOT
void at86rf231_rx_handler(void)
{
    uint8_t lqi, fcs_rssi;
    /* read packet length */
    at86rf231_read_fifo(&at86rf231_rx_buffer[rx_buffer_next].length, 1);

    /* read psdu, read packet with length as first byte and lqi as last byte. */
    uint8_t *buf = buffer[rx_buffer_next];
    at86rf231_read_fifo(buf, at86rf231_rx_buffer[rx_buffer_next].length);

    /* read lqi which is appended after the psdu */
    lqi = buf[at86rf231_rx_buffer[rx_buffer_next].length - 1];

    /* read fcs and rssi, from a register */
    fcs_rssi = at86rf231_reg_read(AT86RF231_REG__PHY_RSSI);

    /* build package */
    at86rf231_rx_buffer[rx_buffer_next].lqi = lqi;
    /* RSSI has no meaning here, it should be read during packet reception. */
    at86rf231_rx_buffer[rx_buffer_next].rssi = fcs_rssi & 0x0F;  // bit[4:0]
    /* bit7, boolean, 1 FCS valid, 0 FCS not valid */
    at86rf231_rx_buffer[rx_buffer_next].crc = (fcs_rssi >> 7) & 0x01;

    if (at86rf231_rx_buffer[rx_buffer_next].crc == 0) {
        DEBUG("at86rf231: Got packet with invalid crc.\n");
        return;
    }

#ifdef DEBUG_ENABLED
    DEBUG("pkg: ");
    for (int i = 1; i < at86rf231_rx_buffer[rx_buffer_next].length; i++) {
        DEBUG("%x ", buf[i]);
    }
    DEBUG("\n");
#endif

    /* read buffer into ieee802154_frame */
    ieee802154_frame_read(&buf[1], &at86rf231_rx_buffer[rx_buffer_next].frame,
                          at86rf231_rx_buffer[rx_buffer_next].length);

    /* if packet is no ACK */
    if (at86rf231_rx_buffer[rx_buffer_next].frame.fcf.frame_type != IEEE_802154_ACK_FRAME) {
#ifdef DEBUG_ENABLED
        ieee802154_frame_print_fcf_frame(&at86rf231_rx_buffer[rx_buffer_next].frame);
#endif
        if (at86rf231_raw_packet_cb != NULL) {
            at86rf231_raw_packet_cb(&at86rf231_netdev, (void*)buf,
                                    at86rf231_rx_buffer[rx_buffer_next].length,
                                    fcs_rssi, lqi, (fcs_rssi >> 7));
        }
コード例 #3
0
ファイル: mac.c プロジェクト: manoja328/RIOT
void set_ieee802154_fcf_values(ieee802154_frame_t *frame, uint8_t dest_mode,
                               uint8_t src_mode)
{
    frame->fcf.frame_type = IEEE_802154_DATA_FRAME;
    frame->fcf.sec_enb = 0;
    frame->fcf.frame_pend = 0;
    frame->fcf.ack_req = 0;
    frame->fcf.panid_comp = 0;
    frame->fcf.frame_ver = 0;
    frame->fcf.src_addr_m = src_mode;
    frame->fcf.dest_addr_m = dest_mode;
#if ENABLE_DEBUG
    ieee802154_frame_print_fcf_frame(frame);
#endif
}
コード例 #4
0
ファイル: mac.c プロジェクト: Embedded-linux/RIOT
static void *recv_ieee802154_frame(void *arg)
{
    (void) arg;

    msg_t m;
#if (defined(MODULE_AT86RF231) | \
     defined(MODULE_CC2420) | \
     defined(MODULE_MC1322X))
    ieee802154_packet_t *p;
#else
    radio_packet_t *p;
    uint8_t hdrlen;
#endif
    uint8_t length;
    ieee802154_frame_t frame;
    net_if_eui64_t src, dst;

    msg_init_queue(msg_q, RADIO_RCV_BUF_SIZE);

    while (1) {
        msg_receive(&m);

        if (m.type == PKT_PENDING) {
#if (defined(MODULE_AT86RF231) | \
     defined(MODULE_CC2420) | \
     defined(MODULE_MC1322X))
            p = (ieee802154_packet_t *) m.content.ptr;
            memcpy(&frame, &p->frame, sizeof(ieee802154_frame_t));
            length = p->frame.payload_len;
#else
            p = (radio_packet_t *) m.content.ptr;
            hdrlen = ieee802154_frame_read(p->data, &frame, p->length);
            length = p->length - hdrlen - IEEE_802154_FCS_LEN;
#endif

#ifdef DEBUG_ENABLED
            DEBUG("INFO: Received IEEE 802.15.4. packet (length = %d):\n", length);
            DEBUG("INFO: FCF:\n");
            ieee802154_frame_print_fcf_frame(&frame);

            DEBUG("Sender:");

            for (uint8_t i = 0; i < 8; i++) {
                printf("%02x ", frame.src_addr[i]);
            }

            DEBUG("\n");

            DEBUG("Receiver:");

            for (size_t i = 0; i < 8; i++) {
                printf("%02x ", frame.dest_addr[i]);
            }

            DEBUG("\n");

            DEBUG("Payload:\n");

            for (uint8_t i = 0; i < frame.payload_len; i++) {
                printf("%02x ", frame.payload[i]);

                if (!((i + 1) % 16) || i == frame.payload_len - 1) {
                    printf("\n");
                }
            }

#endif

            if (frame.fcf.src_addr_m == IEEE_802154_SHORT_ADDR_M) {
                mac_frame_short_to_eui64(&src, frame.src_addr);
            }
            else if (frame.fcf.src_addr_m == IEEE_802154_LONG_ADDR_M) {
                memcpy(&src, frame.src_addr, 8);
            }
            else {
                DEBUG("Unknown IEEE 802.15.4 source address mode.\n");
                continue;
            }

            if (frame.fcf.dest_addr_m == IEEE_802154_SHORT_ADDR_M) {
                mac_frame_short_to_eui64(&dst, frame.dest_addr);
            }
            else if (frame.fcf.dest_addr_m == IEEE_802154_LONG_ADDR_M) {
                memcpy(&dst, frame.dest_addr, 8);
            }
            else {
                DEBUG("Unknown IEEE 802.15.4 destination address mode.\n");
                continue;
            }

            /* deliver packet to network(6lowpan)-layer */
            lowpan_read(frame.payload, length, &src, &dst);
            /* TODO: get interface ID somehow */

            p->processing--;
        }
        else if (m.type == ENOBUFFER) {
            DEBUG("Transceiver buffer full");
        }
        else {
            DEBUG("Unknown packet received");
        }
    }

    return NULL;
}