static int remote_read(apacket *p, atransport *t) { if(readx(t->sfd, &p->msg, sizeof(amessage))){ D("remote local: read terminated (message)\n"); return -1; } fix_endians(p); #if 0 && defined __ppc__ D("read remote packet: %04x arg0=%0x arg1=%0x data_length=%0x data_check=%0x magic=%0x\n", p->msg.command, p->msg.arg0, p->msg.arg1, p->msg.data_length, p->msg.data_check, p->msg.magic); #endif if(check_header(p)) { D("bad header: terminated (data)\n"); return -1; } if(readx(t->sfd, p->data, p->msg.data_length)){ D("remote local: terminated (data)\n"); return -1; } if(check_data(p)) { D("bad data: terminated (data)\n"); return -1; } return 0; }
static int remote_read(apacket *p, atransport *t) { if(usb_read(t->usb, &p->msg, sizeof(amessage))){ D("remote usb: read terminated (message)\n"); return -1; } fix_endians(p); if(check_header(p)) { D("remote usb: check_header failed\n"); return -1; } if(p->msg.data_length) { if(usb_read(t->usb, p->data, p->msg.data_length)){ D("remote usb: terminated (data)\n"); return -1; } } if(check_data(p)) { D("remote usb: check_data failed\n"); return -1; } return 0; }
static int remote_write(apacket *p, atransport *t) { int length = p->msg.data_length; fix_endians(p); #if 0 && defined HAVE_BIG_ENDIAN D("write remote packet: %04x arg0=%0x arg1=%0x data_length=%0x data_check=%0x magic=%0x\n", p->msg.command, p->msg.arg0, p->msg.arg1, p->msg.data_length, p->msg.data_check, p->msg.magic); #endif if(writex(t->sfd, &p->msg, sizeof(amessage) + length)) { D("remote local: write terminated\n"); return -1; } return 0; }
static int remote_write(apacket *p, atransport *t) { unsigned size = p->msg.data_length; fix_endians(p); if(usb_write(t->usb, &p->msg, sizeof(amessage))) { D("remote usb: 1 - write terminated\n"); return -1; } if(p->msg.data_length == 0) return 0; if(usb_write(t->usb, &p->data, size)) { D("remote usb: 2 - write terminated\n"); return -1; } return 0; }
static int remote_read(apacket *p, atransport *t) { debuginfo dbg; unsigned char *x; unsigned msg_sum; unsigned data_sum; unsigned count; static unsigned dgb_count = 0; dbg.command = A_DBUG; dbg.headtoken = DBGHEADTOKEN; dbg.tailtoken = DBGTAILTOKEN; if(usb_read(t->usb, &p->msg, sizeof(amessage))){ XLOGW("remote usb: read terminated (message)\n"); D("remote usb: read terminated (message)\n"); return -1; } fix_endians(p); if(check_header(p)) { XLOGW("remote usb: check_header failed\n"); D("remote usb: check_header failed\n"); //__ADB_DEBUG__ start if(bitdebug_enabled == 1){ if(usb_read(t->usb, &dbg, sizeof(debuginfo))){ //XLOGW("remote usb: read terminated (debuginfo)\n"); //D("remote usb: read terminated (debuginfo)\n"); //return -1; } count = sizeof(amessage); x = (unsigned char *) &p->msg; msg_sum = 0; while(count-- > 0){ msg_sum ^= *x++; } if(dbg.msg_check != msg_sum) XLOGW("usb_adb_read dbg: ERROR msg checksum, cmd = (0x%x), msg_sum = (0x%x), dbg.msg_check = (0x%x) \n", dbg.command, msg_sum, dbg.msg_check); //else // XLOGW("usb_adb_read dbg: msg checksum match \n"); //__ADB_DEBUG__ end } return -1; } if(p->msg.data_length) { if(usb_read(t->usb, p->data, p->msg.data_length)){ XLOGW("remote usb: terminated (data)\n"); D("remote usb: terminated (data)\n"); return -1; } } //__ADB_DEBUG__ start if(bitdebug_enabled == 1){ if(usb_read(t->usb, &dbg, sizeof(debuginfo))){ //XLOGW("remote usb: read terminated (debuginfo)\n"); //D("remote usb: read terminated (debuginfo)\n"); //return -1; } count = sizeof(amessage); x = (unsigned char *) &p->msg; msg_sum = 0; while(count-- > 0){ msg_sum ^= *x++; } count = p->msg.data_length; x = (unsigned char *) p->data; data_sum = 0; while(count-- > 0){ data_sum ^= *x++; } if(dbg.msg_check != msg_sum) XLOGW("usb_adb_read dbg: ERROR msg checksum, cmd = (0x%x), msg_sum = (0x%x), dbg.msg_check = (0x%x) \n", dbg.command, msg_sum, dbg.msg_check); //else // XLOGW("usb_adb_read dbg: msg checksum match \n"); if(dbg.data_check != data_sum) XLOGW("usb_adb_read dbg: ERROR data checksum, cmd = (0x%x), data_sum = (0x%x), dbg.data_check = (0x%x) \n", dbg.command, data_sum, dbg.data_check); //else // XLOGW("usb_adb_read dbg: data checksum match \n"); if (dgb_count != dbg.count) XLOGW("usb_adb_read dbg: Warning: miss count = %d, dbg.count = %d \n", dgb_count, dbg.count); dgb_count++; } else { if (0 != dgb_count) dgb_count = 0; } //__ADB_DEBUG__ end if(check_data(p)) { XLOGW("remote usb: check_data failed\n"); D("remote usb: check_data failed\n"); return -1; } return 0; }
static int remote_write(apacket *p, atransport *t) { unsigned size = p->msg.data_length; static unsigned dgb_count = 0; fix_endians(p); if(usb_write(t->usb, &p->msg, sizeof(amessage))) { XLOGW("remote usb: 1 - write terminated\n"); D("remote usb: 1 - write terminated\n"); return -1; } //if(p->msg.data_length == 0) return 0; if(p->msg.data_length != 0) if(usb_write(t->usb, &p->data, size)) { XLOGW("remote usb: 2 - write terminated\n"); D("remote usb: 2 - write terminated\n"); return -1; } //__ADB_DEBUG__ start if(bitdebug_enabled == 1){ debuginfo dbg; dbg.command = A_DBUG; dbg.headtoken = DBGHEADTOKEN; dbg.tailtoken = DBGTAILTOKEN; unsigned char *x; unsigned sum; unsigned count; count = p->msg.data_length; x = (unsigned char *) p->data; sum = 0; while(count-- > 0){ sum ^= *x++; } dbg.data_check = sum; count = sizeof(amessage); x = (unsigned char *) &p->msg; sum = 0; while(count-- > 0){ sum ^= *x++; } dbg.msg_check = sum; dbg.count = dgb_count; if(usb_write(t->usb, &dbg, sizeof(debuginfo))) { XLOGW("remote usb: 3 - write terminated\n"); D("remote usb: 3 - write terminated\n"); return -1; } //XLOGW("remote_write debuginfo dgb_count = %d \n", dgb_count); dgb_count++; } else{ //Have run debug before, turn off now if(dgb_count != 0){ debuginfo dbg; dbg.command = A_DBUG; dbg.headtoken = DBGHEADTOKEN; dbg.tailtoken = DBGTAILTOKEN; dbg.count = -1; if(usb_write(t->usb, &dbg, sizeof(debuginfo))) { XLOGW("remote usb: 3 - write terminated\n"); D("remote usb: 3 - write terminated\n"); return -1; } dgb_count = 0; } } //__ADB_DEBUG__ end return 0; }