bladox.com Forum Index bladox.com
Turbo SIM Toolkit Adapter Forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

RUN_GSM_ALGORITHM unexpected behaviour

 
Post new topic   Reply to topic    bladox.com Forum Index -> Development
View previous topic :: View next topic  
Author Message
belve



Joined: 04 May 2006
Posts: 30

PostPosted: Tue Jul 17, 2012 8:12 pm    Post subject: RUN_GSM_ALGORITHM unexpected behaviour Reply with quote

Interesting....
After inserting very simple code such as
void turbo_handler (u8 action, void *data)
{
switch (action)
{
case ACTION_APP_INIT: .....
reg_action (ACTION_RUN_GSM_ALGORITHM);
break;.....

case ACTION_RUN_GSM_ALGORITHM:
break;....

default:
break;
}
}

ME connects to a network, works and in a short time loses the network and can not connect to the network again. If remove every RUN_GSM_ALGORITHM everything is fine. Even if enter only reg_action(ACTION_RUN_GSM_ALGORITHM) is enough to lose the network. ME loses the network after the first RUN_GSM_ALGORITHM APDU (INS is 8Cool from ME to SIM. Any idea why? Thanks a lot in advance.
Back to top
View user's profile Send private message
belve



Joined: 04 May 2006
Posts: 30

PostPosted: Tue Jul 17, 2012 8:13 pm    Post subject: Reply with quote

APDU INS is 88 from ME to SIM
Back to top
View user's profile Send private message
pz



Joined: 12 Mar 2004
Posts: 1161

PostPosted: Wed Jul 18, 2012 8:02 am    Post subject: Reply with quote

The question is how you handle the ACTION_RUN_GSM_ALGORITHM - this is critical to connect to the network. If just "break" as you write above then of course the phone can't connect because wrong answer (garbage in this case) is sent.

See fake_sim app for example.
Back to top
View user's profile Send private message
belve



Joined: 04 May 2006
Posts: 30

PostPosted: Wed Jul 18, 2012 3:54 pm    Post subject: Reply with quote

OK I will see and use fake_sim again. But if to register the ACTION_RUN_GSM_ event... and insert only case ACTION_APP_INIT: ..... reg_action (ACTION_RUN_GSM_ALGORITHM); break;..... without code to handle the event and without case ACTION_RUN_GSM... section at all I have got the same result. ME loses the network after the first APDU INS is 88 from ME to SIM and can not connect again.
I have supposed before that if ME started RUN_GSM_ALGORITHM so ME and SIM should itself handle and finish correctly the procedure and the result does not depend from my code in the section case ACTION_RUN_GSM_ALGORITHM: ?. break; For example if I would like to insert in the case section to handle ACTION_RUN_GSM_ALGORITHM event simple code to write\read some data to EEPROM so do not need to write full code to finish the procedure as APDU INS 88 requests because ME and SIM does everything self-sufficient.
But after your reply I understood that should to handle ACTION_RUN_GSM? in the manner like in fake_sim and to write complete code to start and finish ACTION_RUN_GSM? correctly and independently what ME and SIM do?
Back to top
View user's profile Send private message
pz



Joined: 12 Mar 2004
Posts: 1161

PostPosted: Thu Jul 19, 2012 1:25 pm    Post subject: Reply with quote

Once you register ACTION_RUN_GSM_ALGORITHM then it's on you to handle it, it doesn't go to SIM. Your app gets the action even if you don't have 'case ACTION_RUN_GSM_ALGORITHM:'. The simplest code would be that you pass it to SIM with sim(). Btw. don't forget to handle also the GET_RESPONSE. See fakesim app.
Back to top
View user's profile Send private message
belve



Joined: 04 May 2006
Posts: 30

PostPosted: Thu Jul 19, 2012 2:12 pm    Post subject: Reply with quote

OK Pavel Thanks for the feedback. Will try.
Back to top
View user's profile Send private message
belve



Joined: 04 May 2006
Posts: 30

PostPosted: Fri Jul 27, 2012 3:11 pm    Post subject: Reply with quote

Sorry gentlemen. I can not to catch and handle GET RESPONSE event after RUN_GSM_ALGORITHM in the frame of case RUN_GSM_ALGORITHM handling.
So when RUN_GSM_ALGORITHM occurred and I have started to handle it everything is OK. But then I can not execute sim(ME_CMD_GET_RESPONSE,0x00,0x00,0x0C, fa->data) correctly because can not catch GET_RESPONSE event and as a result is impossible to finish RUN_GSM_ correctly to send form SIM to ME SRES and Kc calculated. Interesting that PREV_INS and current INS in File_apdu_data are the same too (see APDU flow).

CODE
void run_gsm (File_apdu_data * fa)//the func to handle RUN_GSM_ALGORITHM and GET_RESPONSE
{
if (fa->ins == ME_CMD_RUN_GSM_ALGORITHM)
{
dbsp ("PREV_INS0:"); dbch (fa->prev_ins); //just a token to debug
dbsp ("INS0:"); dbch (fa->ins); //just a token to debug

sim(ME_CMD_RUN_GSM_ALGORITHM,0x00,0x00,0x10, fa->data);
}
dbsp ("INS1:"); dbch (fa->ins); //just a token to debug
dbsp ("PREV_INS1:"); dbch (fa->prev_ins); //just a token to debug
delayMs(100); //Trying to wait to transfer 9f 0c from SIM to ME but not result before GET RESPONSE
dbsp ("INS2:"); dbch (fa->ins); //just a token to debug
dbsp ("PREV_INS2:"); dbch (fa->prev_ins); //just a token to debug

//not occurred because PREV_INS and current INS in File_apdu_data are the same all time of handling
if (fa->prev_ins == ME_CMD_RUN_GSM_ALGORITHM
&& fa->ins == ME_CMD_GET_RESPONSE)
{
dbsp ("SIM GET RESPONSE ANSWER before:"); //just a token to debug

sim(ME_CMD_GET_RESPONSE,0x00,0x00,0x0C, fa->data);
return;
}
dbsp ("NOT GET RESPONSE");//just a token to debug
dbsp ("INS3:"); dbch (fa->ins); //just a token to debug
dbsp ("PREV_INS3:"); dbch (fa->prev_ins); //just a token to debug
}
APDU
RUN_GSM_ALGORITHM is OK
19.843 FROM ME: a0 88 00 00 10
19.843 FROM ME: 37 3a 3d 64 f5 ea df 29 81 b0 f7 8d 63 d9 ac 8a
19.843 INS000:88 PREV_INS000:88 PREV_INS0:88 INS0:88 TO SIM: a0 88 00 00 10
19.843 TO SIM: 37 3a 3d 64 f5 ea df 29 81 b0 f7 8d 63 d9 ac 8a
19.875 FROM SIM: 9f 0c
19.875 INS1:88 PREV_INS1:88 INS2:88 PREV_INS2:88 NOT GET RESPONSE INS3:88 PREV_INS3:88
TO ME: 9f 0c //transferred when the func finished handling already
WRONG RESPONSE of course and SRES an Kc are wrong. As aresult the network connection will be terminated
20.406
20.406 FROM ME: a0 c0 00 00 0c
20.406 TO ME: a0 c0 00 00 0c ea df 29 81 b0 f7 8d 63 d9 //wrong calculation and the network connection will be terminated of course
Back to top
View user's profile Send private message
belve



Joined: 04 May 2006
Posts: 30

PostPosted: Fri Jul 27, 2012 4:45 pm    Post subject: Reply with quote

I have found some answer in the Forum
http://www.bladox.com/forum/viewforum.php?f=3&topicdays=0&start=150
but without explanation how to catch GET_RESPONSE
Back to top
View user's profile Send private message
belve



Joined: 04 May 2006
Posts: 30

PostPosted: Fri Jul 27, 2012 5:48 pm    Post subject: Reply with quote

Sorry but probably the problem is has been resolved. I inserted extra case ACTION_FILE_APDU and caught and handled GET_RESPONSE event correctly. But it is a little bit strange. Because I read before in Bladox on-line doc #define ACTION_FILE_APDU and Invoked when ME requests file registered by the reg_file() call.
But I have not registered any ef or 6f file and even ACTION_FILE_APDU at all. So? As I understood the action ACTION_FILE_APDU will occur every apdu interaction. Or any? But does not matter. It works and thanks BLADOX.
case ACTION_FILE_APDU:
if (((File_apdu_data *) data)->prev_ins == ME_CMD_RUN_GSM_ALGORITHM
&& ((File_apdu_data *) data)->ins == ME_CMD_GET_RESPONSE)
{
run_gsm_get_response (data);
}
break;

37.546 FROM ME: a0 88 00 00 10
37.593 FROM ME: 6c de d9 1e 20 41 2b a3 88 5a d1 7a e1 9a 8f 06
37.609 INS000:88PREV_INS000:88PREV_INS0:88INS0:88TO SIM: a0 88 00 00 10
37.625 TO SIM: 6c de d9 1e 20 41 2b a3 88 5a d1 7a e1 9a 8f 06
37.703 FROM SIM: 9f 0c
37.703 TO ME: 9f 0c
37.703
37.734 FROM ME: a0 c0 00 00 0c
37.734 SIM GET RESPONSE ANSWER before:TO SIM: a0 c0 00 00 0c
37.765 FROM SIM: 91 d2 5d 40 7a 42 74 2d e2 7e 6c 00 90 00
37.781 SIM GET RESPONSE ANSWER after:91 d2 5d 40 7a 42 74 2d e2 7e 6c 00 90 00
37.796 INS3:c0PREV_INS3:88TO ME: 91 d2 5d 40 7a 42 74 2d e2 7e 6c 00 90 00
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    bladox.com Forum Index -> Development All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group