Register

Protocol 7.00 - Resend request ?

Discuss issues related to Calculator Hacking/Modding.
Senior Member
User avatar
Posts: 101
Joined: Sun Mar 27, 2016 10:24 am
Location: France
Calculators: Casio Afx 1.0, Casio fx-9860GII, Casio fx-CG50

Protocol 7.00 - Resend request ?

Postby cakeisalie5 » Sat Aug 20, 2016 10:33 am

Hello,

I am creating a lib that implements protocol 7.00 as described in the fxReverse project documentation (2nd edition). You can see the project here.

I am trying to implement file sending protocol. But the calculator answers weirdly. This is basically the packet flow I obtain :

=> check(initial)
<= ack
=> command (0x45)
<= ack
=> data
<= resend

And as I interpreted the "resend request" as a response to bad checksum (which is not the case here), the lib then resends the packet, then the calculator sends again the resend request, and it loops until the calculator just ends up sending an empty bulk so my lib would let her alone. Here are my logs if you're interested :

Logs: Show
Code: Select all
[libp7 info]  p7_init: creating libusb context
[libp7 info]  p7_init: getting the device handler
[libp7 info]  p7_start: sending initial check packet
[libp7 info]  p7_send_basic: sending the following basic packet :
[libp7 info]  0530 3030 3730                          .00070
[libp7 info]  p7_recv_main: receiving the packet...
[libp7 info]  p7_recv_main: received the following packet :
[libp7 info]  0630 3030 3730                          .00070
[libp7 info]  p7_recv_main: packet was interpreted as an ack one
[libp7 info]  p7_start: receiving packet info
[libp7 info]  p7_sendfile: calculating given file size
[libp7 info]  p7_sendfile: filesize is 695o
[libp7 info]  p7_sendfile: sending file transfer packet
[libp7 info]  p7_send_ext: sending the following extended packet :
[libp7 info]  0134 3531 3030 3232 0032 3030 2020 2020 .4510022.200   
[libp7 info]  2032 4237 3030 3036 3030 3030 3034 3030  2B7000600000400
[libp7 info]  6D61 696E 2E63 666C 7330 4430           main.cfls0D0
[libp7 info]  p7_recv_main: receiving the packet...
[libp7 info]  p7_recv_main: received the following packet :
[libp7 info]  0630 3030 3730                          .00070
[libp7 info]  p7_recv_main: packet was interpreted as an ack one
[libp7 info]  p7_sendfile: receiving file transfer answer
[libp7 info]  p7_sendfile: about to send 3 packets
[libp7 info]  p7_sendfile: last one is irregular and contains 183o
[libp7 info]  p7_sendfile: sending packet 1/3 (256o)
[libp7 info]  p7_send_ext: sending the following extended packet :
[libp7 info]  0230 3031 3031 3236 0030 3033 3030 3031 .0010126.0030001
[libp7 info]  2369 6E63 6C75 6465 203C 7374 6469 6F2E #include <stdio.
[libp7 info]  683E 5C2A 2369 6E63 6C75 6465 203C 6C69 h>\*#include <li
[libp7 info]  6270 372E 683E 5C2A 5C2A 2F2A 2A5C 2A20 bp7.h>\*\*/**\*
[libp7 info]  2A5C 296D 6169 6E3A 5C2A 202A 5C29 5573 *\)main:\* *\)Us
[libp7 info]  6572 2065 6E74 7279 2070 6F69 6E74 206F er entry point o
[libp7 info]  6620 7468 6520 7072 6F67 7261 6D2E 5C2A f the program.\*
[libp7 info]  202A 2F5C 2A5C 2A69 6E74 206D 6169 6E28  */\*\*int main(
[libp7 info]  766F 6964 295C 2A7B 5C2A 5C29 6368 6172 void)\*{\*\)char
[libp7 info]  2075 7365 726E 616D 655B 395D 3B5C 2A5C  username[9];\*\
[libp7 info]  2A5C 292F 2A20 496E 6974 6961 6C69 7A65 *\)/* Initialize
[libp7 info]  206C 6962 7037 202A 2F5C 2A5C 2969 6620  libp7 */\*\)if
[libp7 info]  2821 7037 5F69 6E69 7428 2929 207B 5C2A (!p7_init()) {\*
[libp7 info]  5C29 5C29 7072 696E 7466 2822 436F 756C \)\)printf("Coul
[libp7 info]  646E 2774 2069 6E69 7469 616C 697A 6520 dn't initialize
[libp7 info]  6C69 6270 3720 3A20 2573 5C5C 6E22 2C20 libp7 : %s\\n",
[libp7 info]  7037 5F67 6574 6572 726F 7228 2929 3B5C p7_geterror());\
[libp7 info]  2A5C 295C 2972 6574 7572 6E20 2833 293B *\)\)return (3);
[libp7 info]  5C2A 5C29 7D5C 2A5C 2A5C 292F 2A20 3243 \*\)}\*\*\)/* 2C
[libp7 info]  p7_recv_main: receiving the packet...
[libp7 info]  p7_recv_main: received the following packet :
[libp7 info]  1530 3130 3646                          .0106F
[libp7 info]  p7_recv_main: packet was interpreted as an error one
[libp7 info]  p7_recv_main: error is 'should resend' (0x1)
[libp7 warn]  p7_send_ext: resend request was received, resend it goes
[libp7 info]  p7_recv_main: receiving the packet...
[libp7 info]  p7_recv_main: received the following packet :
[libp7 info]  1530 3130 3646                          .0106F
[libp7 info]  p7_recv_main: packet was interpreted as an error one
[libp7 info]  p7_recv_main: error is 'should resend' (0x1)
[libp7 warn]  p7_send_ext: resend request was received, resend it goes
[libp7 info]  p7_recv_main: receiving the packet...
[libp7 info]  p7_recv_main: received the following packet :
[libp7 info]  1530 3130 3646                          .0106F
[libp7 info]  p7_recv_main: packet was interpreted as an error one
[libp7 info]  p7_recv_main: error is 'should resend' (0x1)
[libp7 warn]  p7_send_ext: resend request was received, resend it goes
[libp7 info]  p7_recv_main: receiving the packet...
[libp7 info]  p7_recv_main: received the following packet :
[libp7 info]  1530 3130 3646                          .0106F
[libp7 info]  p7_recv_main: packet was interpreted as an error one
[libp7 info]  p7_recv_main: error is 'should resend' (0x1)
[libp7 warn]  p7_send_ext: resend request was received, resend it goes
[libp7 info]  p7_recv_main: receiving the packet...
[libp7 info]  p7_recv_main: received the following packet :
[libp7 info]  1530 3130 3646                          .0106F
[libp7 info]  p7_recv_main: packet was interpreted as an error one
[libp7 info]  p7_recv_main: error is 'should resend' (0x1)
[libp7 warn]  p7_send_ext: resend request was received, resend it goes
[libp7 info]  p7_recv_main: receiving the packet...
[libp7 info]  p7_recv_main: received the following packet :
[libp7 info]  1530 3130 3646                          .0106F
[libp7 info]  p7_recv_main: packet was interpreted as an error one
[libp7 info]  p7_recv_main: error is 'should resend' (0x1)
[libp7 warn]  p7_send_ext: resend request was received, resend it goes
[libp7 info]  p7_recv_main: receiving the packet...
[libp7 info]  p7_recv_main: received the following packet :
[libp7 info]  1530 3130 3646                          .0106F
[libp7 info]  p7_recv_main: packet was interpreted as an error one
[libp7 info]  p7_recv_main: error is 'should resend' (0x1)
[libp7 warn]  p7_send_ext: resend request was received, resend it goes
[libp7 info]  p7_recv_main: receiving the packet...
[libp7 info]  p7_recv_main: received the following packet :
[libp7 info]  (nothing)
Couldn't send file : no error have been encountered
[libp7 info]  p7_term: sending terminate packet
[libp7 info]  p7_send_basic: sending the following basic packet :
[libp7 info]  1830 3030 3730                          .00070
[libp7 info]  p7_recv_main: receiving the packet...
[libp7 info]  p7_recv_main: received the following packet :
[libp7 info]  1530 3130 3646                          .0106F
[libp7 info]  p7_recv_main: packet was interpreted as an error one
[libp7 info]  p7_recv_main: error is 'should resend' (0x1)
[libp7 warn]  p7_send_basic: resend request was received, resend it goes
[libp7 info]  p7_recv_main: receiving the packet...
[libp7 info]  p7_recv_main: received the following packet :
[libp7 info]  0630 3030 3730                          .00070
[libp7 info]  p7_recv_main: packet was interpreted as an ack one


I came here to ask : am I getting the theory right, or should I not resend the data packet but the command packet above ? What could be the cause of this ?

Thanks in advance for your help :)
Part of the Planète Casio community (FR) - main author of Cahute

Senior Member
User avatar
Posts: 605
Joined: Sat Sep 15, 2012 6:59 am
Location: Krautland ****
Calculators: Casio fx-7400GII, Casio fx-7400GII (SH4), Casio fx-9750GII, Casio fx-9750GII (SH4), Casio fx-9860G, Casio fx-9860G SD, Casio fx-9860G Slim, Casio fx-9860GII SD, Casio fx-9860GII SD Power Graphic 2, Casio Classpad 330 plus, Casio fx-CG20, Casio fx-CG50, Casio Classpad fx-CP400

Re: Protocol 7.00 - Resend request ?

Postby SimonLothar » Sat Aug 20, 2016 11:16 am

I am not sure, but your main data packet looks like you did no 0x5C-padding.
You must transform any data byte b < 0x20 to 0x5C,b and 0x5c to 0x5c,0x5c before transmitting the data packet.
This is because protocol 7.00 uses control codes below 0x20.
If you receive data, you have to reverse the 0x5c-padding.
I'll be back!

Senior Member
User avatar
Posts: 101
Joined: Sun Mar 27, 2016 10:24 am
Location: France
Calculators: Casio Afx 1.0, Casio fx-9860GII, Casio fx-CG50

Re: Protocol 7.00 - Resend request ?

Postby cakeisalie5 » Sat Aug 20, 2016 11:30 am

That's what I did ^^

For example, on the third line of the data packet, '\n' (0x0A), is transformed to 0x5C2A :)

(file i'm sending (which is also the source code of the test) : )
hidden: Show
Code: Select all
#include <stdio.h>
#include <libp7.h>

/**
 *   main:
 *   User entry point of the program.
 */

int main(void)
{
   char username[9];

   /* Initialize libp7 */
   if (!p7_init()) {
      printf("Couldn't initialize libp7 : %s\n", p7_geterror());
      return (3);
   }

   /* Initialize communication */
   if (!p7_start()) {
      printf("Couldn't initialize communication : %s\n", p7_geterror());
      return (3);
   }

   /* Open file */
   FILE *fp = fopen("main.c", "r");
   if (!fp)
      printf("Couldn't open file");

   /* Send file */
   if (!p7_sendfile(fp, NULL, "main.c", "fls0")) {
      printf("Couldn't send file : %s\n", p7_geterror());
   }

   /* Close file */
   close(fp);

   /* Close communication */
   p7_term();

   return (0);
}

(Escaper)
Part of the Planète Casio community (FR) - main author of Cahute

Senior Member
User avatar
Posts: 605
Joined: Sat Sep 15, 2012 6:59 am
Location: Krautland ****
Calculators: Casio fx-7400GII, Casio fx-7400GII (SH4), Casio fx-9750GII, Casio fx-9750GII (SH4), Casio fx-9860G, Casio fx-9860G SD, Casio fx-9860G Slim, Casio fx-9860GII SD, Casio fx-9860GII SD Power Graphic 2, Casio Classpad 330 plus, Casio fx-CG20, Casio fx-CG50, Casio Classpad fx-CP400

Re: Protocol 7.00 - Resend request ?

Postby SimonLothar » Sat Aug 20, 2016 11:42 am

cakeisalie5 wrote:That's what I did ^^
Yes, sry, I overlooked that. I have to consult very old source code now. Could take some time.
I'll be back!

Senior Member
User avatar
Posts: 605
Joined: Sat Sep 15, 2012 6:59 am
Location: Krautland ****
Calculators: Casio fx-7400GII, Casio fx-7400GII (SH4), Casio fx-9750GII, Casio fx-9750GII (SH4), Casio fx-9860G, Casio fx-9860G SD, Casio fx-9860G Slim, Casio fx-9860GII SD, Casio fx-9860GII SD Power Graphic 2, Casio Classpad 330 plus, Casio fx-CG20, Casio fx-CG50, Casio Classpad fx-CP400

Re: Protocol 7.00 - Resend request ?

Postby SimonLothar » Sat Aug 20, 2016 4:34 pm

I just logged a transfer on my system. This is the ST "45" packet, which my program constructed:

01 34 35 31 30 30 32 37 30 32 30 30 30 30 30 30 .451002702000000
46 45 31 38 30 30 30 42 30 30 30 30 30 34 30 30 FE18000B00000400
49 4E 53 49 47 48 54 2E 47 31 41 66 6C 73 30 35 INSIGHT.G1Afls05
46 F

This is the ST "45" packet out of your log

[libp7 info] 0134 3531 3030 3232 0032 3030 2020 2020 .4510022.200
[libp7 info] 2032 4237 3030 3036 3030 3030 3034 3030 2B7000600000400
[libp7 info] 6D61 696E 2E63 666C 7330 4430 main.cfls0D0

The 8 byte filesize (2B7) is preceded by spaces (0x20). It should be 5 ASCII-zeros (0x30).

OW should be set to "02". In your packet the "2" is preceded by a binary zero. It should be an ASCII-zero.
I'll be back!

Senior Member
User avatar
Posts: 101
Joined: Sun Mar 27, 2016 10:24 am
Location: France
Calculators: Casio Afx 1.0, Casio fx-9860GII, Casio fx-CG50

Re: Protocol 7.00 - Resend request ?

Postby cakeisalie5 » Sat Aug 20, 2016 4:55 pm

Oh god, you're right Oo
I've fixed the size-thing, but I don't know where the binary zero comes from. I'll investigate.

Thanks soooo much <3
Part of the Planète Casio community (FR) - main author of Cahute

Senior Member
User avatar
Posts: 101
Joined: Sun Mar 27, 2016 10:24 am
Location: France
Calculators: Casio Afx 1.0, Casio fx-9860GII, Casio fx-CG50

Re: Protocol 7.00 - Resend request ?

Postby cakeisalie5 » Sat Aug 20, 2016 7:27 pm

So I've corrected quite some errors related to packets, and now, it should work as hell. But it does not :(

Here is the new test file :
test file: Show
Code: Select all
#include <stdio.h>
#include <libp7.h>

/**
 *   main:
 *   User entry point of the program.
 */

int main(void)
{
   /* Initialize libp7 */
   if (!p7_init()) {
      printf("Couldn't initialize libp7 : %s\n", p7_geterror());
      return (3);
   }

   /* Initialize communication */
   if (!p7_start()) {
      printf("Couldn't initialize communication : %s\n", p7_geterror());
      return (3);
   }

   /* Open file */
   FILE *fp = fopen("main.c", "r");
   if (!fp)
      printf("Couldn't open file");

   /* Send file */
   if (!p7_sendfile(fp, NULL, "main.c", "fls0")) {
      printf("Couldn't send file : %s\n", p7_geterror());
   }

   /* Close file */
   close(fp);

   /* Close communication */
   p7_term();

   return (0);
}

And here are the new logs :
logs: Show
Code: Select all
[libp7 info]  p7_init: creating libusb context
[libp7 info]  p7_init: getting the device handler
[libp7 info]  p7_start: sending initial check packet
[libp7 info]  p7_send_basic: sending the following basic packet :
[libp7 info]  0530 3030 3730                          .00070
[libp7 info]  p7_recv_main: receiving the packet...
[libp7 info]  p7_recv_main: received the following packet :
[libp7 info]  0630 3030 3730                          .00070
[libp7 info]  p7_recv_main: packet was interpreted as an ack one
[libp7 info]  p7_start: receiving packet info
[libp7 info]  p7_sendfile: calculating given file size
[libp7 info]  p7_sendfile: filesize is 675o
[libp7 info]  p7_sendfile: sending file transfer packet
[libp7 info]  p7_send_ext: sending the following extended packet :
[libp7 info]  0134 3531 3030 3232 3032 3030 3030 3030 .451002202000000
[libp7 info]  3032 4133 3030 3036 3030 3030 3034 3030 02A3000600000400
[libp7 info]  6D61 696E 2E63 666C 7330 3535           main.cfls055
[libp7 info]  p7_recv_main: receiving the packet...
[libp7 info]  p7_recv_main: received the following packet :
[libp7 info]  0630 3030 3730                          .00070
[libp7 info]  p7_recv_main: packet was interpreted as an ack one
[libp7 info]  p7_sendfile: receiving file transfer answer
[libp7 info]  p7_sendfile: about to send 3 packets
[libp7 info]  p7_sendfile: last one is irregular and contains 163o
[libp7 info]  p7_sendfile: sending packet 1/3 (256o)
[libp7 info]  p7_send_ext: sending the following extended packet :
[libp7 info]  0230 3031 3031 3233 3030 3033 3030 3031 .001012300030001
[libp7 info]  2369 6E63 6C75 6465 203C 7374 6469 6F2E #include <stdio.
[libp7 info]  683E 5C2A 2369 6E63 6C75 6465 203C 6C69 h>\*#include <li
[libp7 info]  6270 372E 683E 5C2A 5C2A 2F2A 2A5C 2A20 bp7.h>\*\*/**\*
[libp7 info]  2A5C 296D 6169 6E3A 5C2A 202A 5C29 5573 *\)main:\* *\)Us
[libp7 info]  6572 2065 6E74 7279 2070 6F69 6E74 206F er entry point o
[libp7 info]  6620 7468 6520 7072 6F67 7261 6D2E 5C2A f the program.\*
[libp7 info]  202A 2F5C 2A5C 2A69 6E74 206D 6169 6E28  */\*\*int main(
[libp7 info]  766F 6964 295C 2A7B 5C2A 5C29 2F2A 2049 void)\*{\*\)/* I
[libp7 info]  6E69 7469 616C 697A 6520 6C69 6270 3720 nitialize libp7
[libp7 info]  2A2F 5C2A 5C29 6966 2028 2170 375F 696E */\*\)if (!p7_in
[libp7 info]  6974 2829 2920 7B5C 2A5C 295C 2970 7269 it()) {\*\)\)pri
[libp7 info]  6E74 6628 2243 6F75 6C64 6E27 7420 696E ntf("Couldn't in
[libp7 info]  6974 6961 6C69 7A65 206C 6962 7037 203A itialize libp7 :
[libp7 info]  2025 735C 5C6E 222C 2070 375F 6765 7465  %s\\n", p7_gete
[libp7 info]  7272 6F72 2829 293B 5C2A 5C29 5C29 7265 rror());\*\)\)re
[libp7 info]  7475 726E 2028 3329 3B5C 2A5C 297D 5C2A turn (3);\*\)}\*
[libp7 info]  5C2A 5C29 2F2A 2049 6E69 7469 616C 697A \*\)/* Initializ
[libp7 info]  6520 636F 6D6D 756E 6963 6145 43        e communicaEC
[libp7 info]  p7_recv_main: receiving the packet...
[libp7 info]  p7_recv_main: received the following packet :
[libp7 info]  1530 3130 3646                          .0106F
[libp7 info]  p7_recv_main: packet was interpreted as an error one
[libp7 info]  p7_recv_main: error is 'should resend' (0x1)
[libp7 warn]  p7_send_ext: resend request was received, resend it goes
[libp7 info]  p7_recv_main: receiving the packet...
[libp7 info]  p7_recv_main: received the following packet :
[libp7 info]  1530 3130 3646                          .0106F
[libp7 info]  p7_recv_main: packet was interpreted as an error one
[libp7 info]  p7_recv_main: error is 'should resend' (0x1)
[libp7 warn]  p7_send_ext: resend request was received, resend it goes
[libp7 info]  p7_recv_main: receiving the packet...
[libp7 info]  p7_recv_main: received the following packet :
[libp7 info]  1530 3130 3646                          .0106F
[libp7 info]  p7_recv_main: packet was interpreted as an error one
[libp7 info]  p7_recv_main: error is 'should resend' (0x1)
[libp7 warn]  p7_send_ext: resend request was received, resend it goes
[libp7 info]  p7_recv_main: receiving the packet...
[libp7 info]  p7_recv_main: received the following packet :
[libp7 info]  1530 3130 3646                          .0106F
[libp7 info]  p7_recv_main: packet was interpreted as an error one
[libp7 info]  p7_recv_main: error is 'should resend' (0x1)
[libp7 warn]  p7_send_ext: resend request was received, resend it goes
[libp7 info]  p7_recv_main: receiving the packet...
[libp7 fatal] p7_recv_main: calculator was disconnected
Couldn't send file : couldn't get calculator (plugged and in receive mode ?)
[libp7 info]  p7_term: sending terminate packet
[libp7 info]  p7_send_basic: sending the following basic packet :
[libp7 info]  1830 3030 3730                          .00070
[libp7 fatal] p7_send_basic: calculator was disconnected
[libp7 warn]  p7_term: couldn't send or didn't receive confirmation

(ending interruption is because I'm pressing AC on the calculator)

I've checked manually the two packets and they should be good (I haven't checked the checksum manually as if it works for the command extended packet, it should work for data packet as well).

I've tried adding a folder name (as I just send an empty string in D1, a.k.a. the folder name) and I still get the same problem : infinite resend requests. I don't understand the problem Oo

(distant repository has been updated with corrections)
Part of the Planète Casio community (FR) - main author of Cahute

Senior Member
User avatar
Posts: 605
Joined: Sat Sep 15, 2012 6:59 am
Location: Krautland ****
Calculators: Casio fx-7400GII, Casio fx-7400GII (SH4), Casio fx-9750GII, Casio fx-9750GII (SH4), Casio fx-9860G, Casio fx-9860G SD, Casio fx-9860G Slim, Casio fx-9860GII SD, Casio fx-9860GII SD Power Graphic 2, Casio Classpad 330 plus, Casio fx-CG20, Casio fx-CG50, Casio Classpad fx-CP400

Re: Protocol 7.00 - Resend request ?

Postby SimonLothar » Sun Aug 21, 2016 8:00 am

cakeisalie5 wrote:Thanks soooo much <3
No worries. You are welcome.

cakeisalie5 wrote:[libp7 info] p7_send_ext: sending the following extended packet :
[libp7 info] 0230 3031 3031 3233 3030 3033 3030 3031 .001012300030001
You have to use the same subtype (ST) in the data packet (T=0x02) as in the corresponding command packet (T=0x01).
=>
[libp7 info] 0234 3531 3031 3233 3030 3033 3030 3031 .451012300030001
I'll be back!

Senior Member
User avatar
Posts: 101
Joined: Sun Mar 27, 2016 10:24 am
Location: France
Calculators: Casio Afx 1.0, Casio fx-9860GII, Casio fx-CG50

Re: Protocol 7.00 - Resend request ?

Postby cakeisalie5 » Sun Aug 21, 2016 10:14 am

Ah crap, I didn't realize that :o

It works perfectly now. Thanks <3
Part of the Planète Casio community (FR) - main author of Cahute

Return to Calculator Hacking/Modding Discussions

Who is online

Users browsing this forum: No registered users and 24 guests