@@ -109,12 +109,13 @@ microtime (void)
109
109
110
110
111
111
void
112
- print_error (FILE * out , double timestamp , struct sockaddr_in * reader_addr , char * error_msg , uint32_t error_code )
112
+ print_error (FILE * out , double timestamp , struct sockaddr_in * reader_addr , uint16_t reader_id , char * error_msg , uint32_t error_code )
113
113
{
114
114
fprintf (out , "{" );
115
115
116
- fprintf (out , "\"reader\": {\"ip\":\"%s\",\"t\":%d}," ,
116
+ fprintf (out , "\"reader\": {\"ip\":\"%s\",\"id\":%d,\" t\":%d}," ,
117
117
inet_ntoa (reader_addr -> sin_addr ),
118
+ reader_id ,
118
119
(uint32_t ) timestamp );
119
120
120
121
fprintf (out , "\"error\": \"%s (%d)\"" , error_msg , error_code );
@@ -126,22 +127,29 @@ print_error(FILE *out, double timestamp, struct sockaddr_in *reader_addr, char *
126
127
127
128
128
129
void
129
- print_packet (FILE * out , double timestamp , struct sockaddr_in * reader_addr , const TBeaconNgTracker * track )
130
+ print_packet (FILE * out , double timestamp , struct sockaddr_in * reader_addr , uint16_t reader_id , const uint8_t * signature , const TBeaconNgTracker * track )
130
131
{
131
132
uint32_t t ;
133
+ int j ;
132
134
const TBeaconNgSighting * slot ;
133
135
134
136
fprintf (out , "{" );
135
137
136
- fprintf (out , "\"reader\": {\"ip\":\"%s\",\"t\":%d}," ,
138
+ fprintf (out , "\"reader\": {\"ip\":\"%s\",\"id\":%d,\" t\":%d}," ,
137
139
inet_ntoa (reader_addr -> sin_addr ),
140
+ reader_id ,
138
141
(uint32_t ) timestamp );
139
142
140
143
fprintf (out , "\"packet\": {\"id\":\"%08X\",\"t\":%d," ,
141
144
track -> uid ,
142
145
track -> epoch
143
146
);
144
147
148
+ fprintf (out , "\"crc\":\"" );
149
+ for (j = 0 ; j < CONFIG_SIGNATURE_SIZE ; j ++ )
150
+ fprintf (out , "%02X" , signature [j ]);
151
+ fprintf (out , "\"," );
152
+
145
153
/* show specific fields */
146
154
switch (track -> proto )
147
155
{
@@ -204,30 +212,30 @@ parse_packet (double timestamp, struct sockaddr_in *reader_addr, const void *dat
204
212
pkt = (const TBeaconLogSighting * )data ;
205
213
if (pkt -> hdr .protocol != BEACONLOG_SIGHTING )
206
214
{
207
- print_error (stdout , timestamp , reader_addr , "Invalid protocol" , pkt -> hdr .protocol );
215
+ print_error (stdout , timestamp , reader_addr , ntohs ( pkt -> hdr . reader_id ), "Invalid protocol" , pkt -> hdr .protocol );
208
216
//fprintf(stderr, " Invalid protocol [0x%02X]\n\r", pkt->hdr.protocol);
209
217
return len ;
210
218
}
211
219
212
220
t = ntohs (pkt -> hdr .size );
213
221
if (ntohs (t != sizeof (TBeaconLogSighting )))
214
222
{
215
- print_error (stdout , timestamp , reader_addr , "Invalid packet size" , t );
223
+ print_error (stdout , timestamp , reader_addr , ntohs ( pkt -> hdr . reader_id ), "Invalid packet size" , t );
216
224
//fprintf(stderr, " Invalid packet size (%u)\n\r", t);
217
225
return len ;
218
226
}
219
227
220
228
if (ntohs (pkt -> hdr .icrc16 ) != icrc16 (& pkt -> hdr .protocol , (sizeof (TBeaconLogSighting )- sizeof (pkt -> hdr .icrc16 ))))
221
229
{
222
- print_error (stdout , timestamp , reader_addr , "Invalid packet CRC" , 0 );
230
+ print_error (stdout , timestamp , reader_addr , ntohs ( pkt -> hdr . reader_id ), "Invalid packet CRC" , 0 );
223
231
//fprintf(stderr, " Invalid packet CRC\n\r");
224
232
return len ;
225
233
}
226
234
227
235
/* decrypt valid packet */
228
236
if ((t = aes_decr (& pkt -> log , & track , sizeof (track ), CONFIG_SIGNATURE_SIZE ))!= 0 )
229
237
{
230
- print_error (stdout , timestamp , reader_addr , "Packet decryption error" , t );
238
+ print_error (stdout , timestamp , reader_addr , ntohs ( pkt -> hdr . reader_id ), "Packet decryption error" , t );
231
239
//fprintf(stderr, " Failed decrypting packet with error [%i]\n\r", t);
232
240
return len ;
233
241
}
@@ -236,13 +244,13 @@ parse_packet (double timestamp, struct sockaddr_in *reader_addr, const void *dat
236
244
if (!((track .proto == RFBPROTO_BEACON_NG_SIGHTING )||
237
245
(track .proto == RFBPROTO_BEACON_NG_STATUS )))
238
246
{
239
- print_error (stdout , timestamp , reader_addr , "Unkown packet protocol" , track .proto );
247
+ print_error (stdout , timestamp , reader_addr , ntohs ( pkt -> hdr . reader_id ), "Unkown packet protocol" , track .proto );
240
248
//fprintf(stderr, " Unknown protocol [%i]\n\r", track.proto);
241
249
return len ;
242
250
}
243
251
244
252
/* show & process latest packet */
245
- print_packet (stdout , timestamp , reader_addr , & track );
253
+ print_packet (stdout , timestamp , reader_addr , ntohs ( pkt -> hdr . reader_id ), (( uint8_t * ) & pkt -> log ) + sizeof ( track ) - CONFIG_SIGNATURE_SIZE , & track );
246
254
247
255
return sizeof (TBeaconLogSighting );
248
256
}
0 commit comments