/* Check if a packet is for us */ static int is_packet_for_us(uint8_t *buf, int len, int do_send_ack) { frame802154_t frame; int result; uint8_t parsed = frame802154_parse(buf, len, &frame); if(parsed) { if(frame.fcf.dest_addr_mode) { int has_dest_panid; frame802154_has_panid(&frame.fcf, NULL, &has_dest_panid); if(has_dest_panid && frame802154_get_pan_id() != FRAME802154_BROADCASTPANDID && frame.dest_pid != frame802154_get_pan_id() && frame.dest_pid != FRAME802154_BROADCASTPANDID) { /* Packet to another PAN */ return 0; } if(!is_broadcast_addr(frame.fcf.dest_addr_mode, frame.dest_addr)) { result = linkaddr_cmp((linkaddr_t *)frame.dest_addr, &linkaddr_node_addr); if(autoack_enabled && result && do_send_ack) { /* this is a unicast frame and sending ACKs is enabled */ send_ack(&frame); } return result; } } return 1; } else { return 0; } }
static int panid_run_test(const panid_test_def table[], size_t table_size, setup_fcf_p setup_fcf) { int i; int num_of_tests = table_size / sizeof(panid_test_def); frame802154_fcf_t fcf; int has_src_pan_id, has_dest_pan_id; const panid_test_def *test; result_t result; for(i = 0; i < num_of_tests; i++) { test = &table[i]; setup_fcf(test, &fcf); has_src_pan_id = 0; has_dest_pan_id = 0; frame802154_has_panid(&fcf, &has_src_pan_id, &has_dest_pan_id); result = FAILURE; switch(test->dest_panid_mode) { case NOT_PRESENT: if(has_dest_pan_id == 0) { result = SUCCESS; } break; case PRESENT: if(has_dest_pan_id == 1) { result = SUCCESS; } break; } if(result == SUCCESS) { result = FAILURE; switch(test->src_panid_mode) { case NOT_PRESENT: if(has_src_pan_id == 0) { result = SUCCESS; } break; case PRESENT: if(has_src_pan_id == 1) { result = SUCCESS; } break; } } #if VERBOSE == 1 printf("%d, %d, %d, %d, %d\n", test->dest_addr_mode, test->src_addr_mode, has_dest_pan_id, has_src_pan_id, test->panid_cmpr_mode); #else printf("%s", result == SUCCESS ? "." : "E"); #endif if(result == FAILURE) { break; } } printf("\n"); return i; }