int nfc_cmd_snep(char* args) { char *p; if (!args) { cb.log_err("KO: no arguments given\r\n"); return -1; } p = strsep(&args, " "); if (!p) { cb.log_err("KO: no operation given\r\n"); return -1; } if (!strcmp(p, "put")) { ssize_t nrecords; struct nfc_snep_param param = NFC_SNEP_PARAM_INIT(); /* read DSAP */ if (parse_sap("DSAP", &args, ¶m.dsap, 1) < 0) { return -1; } /* read SSAP */ if (parse_sap("SSAP", &args, ¶m.ssap, 1) < 0) { return -1; } /* The emulator supports up to 4 records per NDEF * message. If no records are given, the emulator * will print the current content of the LLCP data- * link buffer. */ nrecords = parse_ndef_msg(&args, ARRAY_SIZE(param.record), param.record); if (nrecords < 0) { return -1; } param.nrecords = nrecords; if (param.nrecords) { /* put SNEP request onto SNEP server */ if (cb.send_dta(nfc_send_snep_put_cb, ¶m) < 0) { /* error message generated in create function */ return -1; } } else { /* put SNEP request onto SNEP server */ if (cb.recv_dta(nfc_recv_snep_put_cb, ¶m) < 0) { /* error message generated in create function */ return -1; } } } else { cb.log_err("KO: invalid operation '%s'\r\n", p); return -1; } return 0; }
bool parse_udp(int length, uint32_t* data){//Parse udp header, false for an unaccepted announcement, true for everything else (including wrong port) DBG("Length udp:%d\n",length); struct udphdr* header = (struct udphdr*)data; if(ntohs(header->dest) != 9875){//destionation port fprintf(stderr,"Port is not 9875 but %d!\n",ntohs(header->dest)); return true; } //Again ignoring checksum return parse_sap(length-8,data+2); }
int nfc_cmd_llcp(char* args) { char *p; if (!args) { cb.log_err("KO: no arguments given\r\n"); return -1; } p = strsep(&args, " "); if (!p) { cb.log_err("KO: no operation given\r\n"); return -1; } if (!strcmp(p, "connect")) { struct nfc_llcp_param param = NFC_LLCP_PARAM_INIT(); /* read DSAP */ if (parse_sap("DSAP", &args, ¶m.dsap, 1) < 0) { return -1; } /* read SSAP */ if (parse_sap("SSAP", &args, ¶m.ssap, 1) < 0) { return -1; } if (cb.send_dta(nfc_llcp_connect_cb, ¶m) < 0) { /* error message generated in create function */ return -1; } } else { cb.log_err("KO: invalid operation '%s'\r\n", p); return -1; } return 0; }