Skip to content

Commit 7684e67

Browse files
committed
Added reader ID to JSON error msgs
1 parent 29f8064 commit 7684e67

File tree

1 file changed

+8
-7
lines changed
  • host/openbeacon-mqtt/src

1 file changed

+8
-7
lines changed

host/openbeacon-mqtt/src/main.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -113,14 +113,15 @@ microtime (void)
113113

114114

115115
void
116-
send_error(double timestamp, struct sockaddr_in *reader_addr, char *error_msg, uint32_t error_code)
116+
send_error(double timestamp, struct sockaddr_in *reader_addr, uint16_t reader_id, char *error_msg, uint32_t error_code)
117117
{
118118
int i = 0;
119119

120120
i += sprintf(buf+i, "{");
121121

122-
i += sprintf(buf+i, "\"reader\": {\"ip\":\"%s\",\"t\":%d},",
122+
i += sprintf(buf+i, "\"reader\": {\"ip\":\"%s\",\"id\":%d,\"t\":%d},",
123123
inet_ntoa(reader_addr->sin_addr),
124+
reader_id,
124125
(uint32_t) timestamp);
125126

126127
i += sprintf(buf+i, "\"error\": \"%s (%d)\"", error_msg, error_code);
@@ -217,30 +218,30 @@ parse_packet (double timestamp, struct sockaddr_in *reader_addr, const void *dat
217218
pkt = (const TBeaconLogSighting*)data;
218219
if(pkt->hdr.protocol != BEACONLOG_SIGHTING)
219220
{
220-
send_error(timestamp, reader_addr, "Invalid protocol", pkt->hdr.protocol);
221+
send_error(timestamp, reader_addr, ntohs(pkt->hdr.reader_id), "Invalid protocol", pkt->hdr.protocol);
221222
//fprintf(stderr, " Invalid protocol [0x%02X]\n\r", pkt->hdr.protocol);
222223
return len;
223224
}
224225

225226
t = ntohs(pkt->hdr.size);
226227
if(ntohs(t != sizeof(TBeaconLogSighting)))
227228
{
228-
send_error(timestamp, reader_addr, "Invalid packet size", t);
229+
send_error(timestamp, reader_addr, ntohs(pkt->hdr.reader_id), "Invalid packet size", t);
229230
//fprintf(stderr, " Invalid packet size (%u)\n\r", t);
230231
return len;
231232
}
232233

233234
if(ntohs(pkt->hdr.icrc16) != icrc16(&pkt->hdr.protocol, (sizeof(TBeaconLogSighting)-sizeof(pkt->hdr.icrc16))))
234235
{
235-
send_error(timestamp, reader_addr, "Invalid packet CRC", 0);
236+
send_error(timestamp, reader_addr, ntohs(pkt->hdr.reader_id), "Invalid packet CRC", 0);
236237
//fprintf(stderr, " Invalid packet CRC\n\r");
237238
return len;
238239
}
239240

240241
/* decrypt valid packet */
241242
if((t = aes_decr(&pkt->log, &track, sizeof(track), CONFIG_SIGNATURE_SIZE))!=0)
242243
{
243-
send_error(timestamp, reader_addr, "Packet decryption error", t);
244+
send_error(timestamp, reader_addr, ntohs(pkt->hdr.reader_id), "Packet decryption error", t);
244245
//fprintf(stderr, " Failed decrypting packet with error [%i]\n\r", t);
245246
return len;
246247
}
@@ -249,7 +250,7 @@ parse_packet (double timestamp, struct sockaddr_in *reader_addr, const void *dat
249250
if(!((track.proto == RFBPROTO_BEACON_NG_SIGHTING)||
250251
(track.proto == RFBPROTO_BEACON_NG_STATUS)))
251252
{
252-
send_error(timestamp, reader_addr, "Unkown packet protocol", track.proto);
253+
send_error(timestamp, reader_addr, ntohs(pkt->hdr.reader_id), "Unkown packet protocol", track.proto);
253254
//fprintf(stderr, " Unknown protocol [%i]\n\r", track.proto);
254255
return len;
255256
}

0 commit comments

Comments
 (0)