bool ieee802154_validate_frame(uint8_t *buf, uint8_t length, struct ieee802154_mpdu *mpdu) { uint8_t *p_buf; if (length > IEEE802154_MTU || length < IEEE802154_MIN_LENGTH) { NET_DBG("Wrong packet length: %d", length); return false; } mpdu->mhr.fs = validate_fc_seq(buf, &p_buf); if (!mpdu->mhr.fs) { return false; } /* ToDo: Support later version's frame types */ if (mpdu->mhr.fs->fc.frame_type > IEEE802154_FRAME_TYPE_MAC_COMMAND) { return false; } mpdu->mhr.dst_addr = validate_addr(p_buf, &p_buf, mpdu->mhr.fs->fc.dst_addr_mode, false); mpdu->mhr.src_addr = validate_addr(p_buf, &p_buf, mpdu->mhr.fs->fc.src_addr_mode, (mpdu->mhr.fs->fc.pan_id_comp)); return validate_payload_and_mfr(mpdu, buf, p_buf, length); }
bool ieee802154_validate_frame(u8_t *buf, u8_t length, struct ieee802154_mpdu *mpdu) { u8_t *p_buf = NULL; if (length > IEEE802154_MTU || length < IEEE802154_MIN_LENGTH) { NET_DBG("Wrong packet length: %d", length); return false; } mpdu->mhr.fs = validate_fc_seq(buf, &p_buf); if (!mpdu->mhr.fs) { return false; } /* ToDo: Support later version's frame types */ if (mpdu->mhr.fs->fc.frame_type > IEEE802154_FRAME_TYPE_MAC_COMMAND) { return false; } mpdu->mhr.dst_addr = validate_addr(p_buf, &p_buf, mpdu->mhr.fs->fc.dst_addr_mode, false); mpdu->mhr.src_addr = validate_addr(p_buf, &p_buf, mpdu->mhr.fs->fc.src_addr_mode, (mpdu->mhr.fs->fc.pan_id_comp)); #ifdef CONFIG_NET_L2_IEEE802154_SECURITY if (mpdu->mhr.fs->fc.security_enabled) { mpdu->mhr.aux_sec = ieee802154_validate_aux_security_hdr(p_buf, &p_buf); if (!mpdu->mhr.aux_sec) { return false; } } #endif return validate_payload_and_mfr(mpdu, buf, p_buf, length); }
/* * Function: get_command * * Description: Parses input file and return valid commands and * and or address to global variables. validates data * before filling globals * * * Inputs: filepointer to infile * * Outputs: None */ void get_command(FILE *fp){ static int first_time = 1; static int eof_valid = 0; static int need_num_pages = 0; static int need_addr = 0; static char token[11]; static int rc; rc = fscanf(fp, "%s", token); if (rc == EOF && !eof_valid) { fprintf(stderr, "invalid EOF in input file; this is fatal\n"); exit (-1); } else if (rc == EOF ) { //printf("rc = EOF\n"); cmd = "EOF"; } else if (first_time && strcmp(token, "-p")== MATCH) { //strcmp returns 0 if match cmd = "p"; first_time = 0; // clear first time flag cause we have been here already need_num_pages = 1; // set flag to require a pagenumber next in input file get_command(fp); } else if (need_num_pages) { available_pf = (u32) strtol(token, NULL, 10); validate_pf_number(available_pf); eof_valid = 1; need_num_pages = 0; } else if (need_addr) { validate_addr(token); need_addr = 0; eof_valid = 1; } else if ( strcmp(token, "w") == MATCH || strcmp(token, "W") == MATCH ) { cmd = "w"; need_addr = 1; get_command(fp); } else if ( strcmp(token, "r") == MATCH || strcmp(token, "R") == MATCH ) { cmd = "r"; need_addr= 1; get_command(fp); } else if (strcmp(token, "-v") == MATCH) { v_flag = 1; cmd = "-v"; } else if (strcmp(token, "-t") == MATCH) { t_flag = 1; cmd = "-t"; } else if (strcmp(token, "-d") == MATCH) { d_flag = 1; cmd = "-d"; } else { fprintf(stderr, "Invalid instruction sequence: got %s\n", token); exit(-1); } first_time = 0; }