static int blsize = 0;
static int clock_offset = 0;
+u_int32_t le32_read(const unsigned char *i) {
+ return le32toh(*(u_int32_t*)i);
+}
+
+u_int16_t le16_read(const unsigned char *i) {
+ return le16toh(*(int16_t*)i);
+}
+
uint
randno(void)
{
fprintf(stderr, "didn't receive full ant-fs header\n");
exit(1);
}
- remaining = blast[12] + blast[13]*256 + blast[14]*256*256 + blast[15]*256*256*256;
- offset = blast[16] + blast[17]*256 + blast[18]*256*256 + blast[19]*256*256*256;
- size = blast[20] + blast[21]*256 + blast[22]*256*256 + blast[23]*256*256*256;
+ remaining = le32_read(blast+12);
+ offset = le32_read(blast+16);
+ size = le32_read(blast+20);
printf("save_antfs_file: remaining=%d offset=%d size=%d\n", remaining, offset, size);
if (remaining > blsize - 24 || remaining > blsize - 24 + 16) {
fprintf(stderr, "unexpected ant-fs packet: header says %d bytes, but received %d\n", size, blsize - 24);
if (verbose) printf("%s (%d bytes)\n", filename, size);
ANT_RequestMessage(chan, MESG_CHANNEL_STATUS_ID); //informative
if (offset+remaining < size) {
+ int16_t crc = le16_read(blast + blsize - 1);
+
printf("=> Starting download: %d %d %d\n", offset, remaining, size);
- start_download(chan, antfsdir[downloadingfilenum].fileno,offset+remaining, blast[blsize-1] * 256 + blast[blsize-2], 0);
+ start_download(chan, antfsdir[downloadingfilenum].fileno,offset+remaining, crc, 0);
return 1;
}
return 0;
if (event == EVENT_RX_BROADCAST) {
}
- cid = cbuf[4]+cbuf[5]*256+cbuf[6]*256*256+cbuf[7]*256*256*256;
+ cid = le32_read(cbuf+4);
memcpy((void *)&id, cbuf+4, 4);
D("cid %08x myid %08x\n", cid, myid);
uint offset, remaining, size;
D("received ant-fs directory\n");
- remaining = blast[12] + blast[13]*256 + blast[14]*256*256 + blast[15]*256*256*256;
- offset = blast[16] + blast[17]*256 + blast[18]*256*256 + blast[19]*256*256*256;
- size = blast[20] + blast[21]*256 + blast[22]*256*256 + blast[23]*256*256*256;
+ remaining = le32_read(blast+12);
+ offset = le32_read(blast+16);
+ size = le32_read(blast+20);
decode_antfs_dir(blast, blsize);
if (offset+remaining < size) {
- start_download(chan, 0, offset+remaining, blast[blsize-1] * 256 + blast[blsize-2], 0);
+ int16_t crc = le16_read(blast + blsize - 1);
+ start_download(chan, 0, offset+remaining, crc, 0);
return 1;
}
}
break;
case MESG_CHANNEL_ID_ID:
- devid = ebuf[1]+ebuf[2]*256;
+ devid = le16_read(ebuf+1);
if (mydev == 0 || devid == mydev%65536) {
D("devid %08x myid %08x\n", devid, myid);
} else {