gnokii-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[patch] (sim)lock info


From: Bertrik Sikken
Subject: [patch] (sim)lock info
Date: Sat, 04 Jan 2003 23:54:12 +0100
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.0.1) Gecko/20020826

Hi all,

Attached is a patch to get info about the locks in a phone
for nk6100 compatible phones.
It also adds a --getlocksinfo option to the gnokii command
line tool.

Example of 'gnokii --getlocksinfo':
Found model "NHM-2"
Message sent: 0x40 / 0x0004
00 01 8a 00                                     |
[Received Ack of type 40, seq:  6]
[Sending Ack of type 40, seq: 1]
Message received: 0x40 / 0x001a
01 01 8a 00 0a 01 03 00 00 20 41 2f ff ff ff ff |           A/ÿÿÿÿ
f0 43 4a 00 00 01 00 00 00 10                   | ðCJ
Received message type 40
MCC+MNC :      20412,    user, CLOSED, counter 1
   GID1 :       434A, factory, CLOSED, counter 0
   GID2 :       0000, factory,   open, counter 0
   MSIN : FFFFFFFFFF, factory,   open, counter 0
Serial device: closing device

The implementation is according to the info in nk6100.txt
(although that is not very specific on all values) and is
loosely based on the code from gammu.
The output is consistent with the info that the Windows
program 'Nokia tool by Jordik v3.21' shows.

I had to add an opt_index enum in gnokii.c but this resulted
in my newly added enun to be equal to 63.
However this is later interpreted as an illegal value
when it is returned by getopt_long. Therefore I changed
the value of the first enum value (OPT_HELP) to 256,
so the enums are out of the range of ascii characters.

Regards,
Bertrik


diff -Nru /home/bertrik/gnokii.clean/common/phones/nk6100.c 
/home/bertrik/gnokii/common/phones/nk6100.c
--- /home/bertrik/gnokii.clean/common/phones/nk6100.c   2003-01-03 
21:59:28.000000000 +0100
+++ /home/bertrik/gnokii/common/phones/nk6100.c 2003-01-04 18:48:00.000000000 
+0100
@@ -130,6 +130,7 @@
 static gn_error ChangeSecurityCode(gn_data *data, struct gn_statemachine 
*state);
 static gn_error get_security_code(gn_data *data, struct gn_statemachine 
*state);
 #endif
+static gn_error get_locks_info(gn_data *data, struct gn_statemachine *state);
 
 static gn_error IncomingPhoneInfo(int messagetype, unsigned char *message, int 
length, gn_data *data, struct gn_statemachine *state);
 static gn_error IncomingPhoneInfo2(int messagetype, unsigned char *message, 
int length, gn_data *data, struct gn_statemachine *state);
@@ -329,6 +330,8 @@
        case GN_OP_GetSecurityCode:
                return get_security_code(data, state);
 #endif
+       case GN_OP_GetLocksInfo:
+               return get_locks_info(data, state);
        case GN_OP_SendDTMF:
                return SendDTMF(data, state);
        case GN_OP_Reset:
@@ -2720,9 +2723,20 @@
 }
 #endif
 
+static gn_error get_locks_info(gn_data *data, struct gn_statemachine *state)
+{
+       unsigned char req[] = {0x00, 0x01, 0x8a, 0x00};
+       gn_error err;
+
+       if (sm_message_send(4, 0x40, req, state)) return GN_ERR_NOTREADY;
+       return sm_block(0x40, data, state);
+}
+
 static gn_error IncomingSecurity(int messagetype, unsigned char *message, int 
length, gn_data *data, struct gn_statemachine *state)
 {
        char *aux, *aux2;
+       char  tmp[24];
+       int i;
 
        switch (message[2]) {
        /* IMEI */
@@ -2744,6 +2758,35 @@
                break;
 #endif
 
+       /* Get (sim)lock info */
+       case 0x8A:
+               for (i = 0; i < 4; i++) {
+                       memset(&data->locks_info[i], 0, sizeof(gn_locks_info));
+               }
+
+               data->locks_info[0].userlock = ((message[5] & 0x01) != 0);
+               data->locks_info[1].userlock = ((message[5] & 0x02) != 0);
+               data->locks_info[2].userlock = ((message[5] & 0x04) != 0);
+               data->locks_info[3].userlock = ((message[5] & 0x08) != 0);
+
+               data->locks_info[0].closed = ((message[6] & 0x01) != 0);
+               data->locks_info[1].closed = ((message[6] & 0x02) != 0);
+               data->locks_info[2].closed = ((message[6] & 0x04) != 0);
+               data->locks_info[3].closed = ((message[6] & 0x08) != 0);
+
+               bin2hex(tmp, message + 9, 12);
+
+               strncpy(data->locks_info[0].data, tmp, 5);
+               strncpy(data->locks_info[1].data, tmp + 16, 4);
+               strncpy(data->locks_info[2].data, tmp + 20, 4);
+               strncpy(data->locks_info[3].data, tmp + 5, 10);
+
+               data->locks_info[0].counter = message[21];
+               data->locks_info[1].counter = message[22];
+               data->locks_info[2].counter = message[23];
+               data->locks_info[3].counter = message[24];
+               break;
+
        /* Get bin ringtone */
        case 0x9e:
                switch (message[4]) {
diff -Nru /home/bertrik/gnokii.clean/gnokii/gnokii.c 
/home/bertrik/gnokii/gnokii/gnokii.c
--- /home/bertrik/gnokii.clean/gnokii/gnokii.c  2003-01-03 23:54:29.000000000 
+0100
+++ /home/bertrik/gnokii/gnokii/gnokii.c        2003-01-04 18:45:51.000000000 
+0100
@@ -90,7 +90,7 @@
 #define GAL_XOR 0x01
 
 typedef enum {
-       OPT_HELP,
+       OPT_HELP = 256,
        OPT_VERSION,
        OPT_MONITOR,
        OPT_ENTERSECURITYCODE,
@@ -152,7 +152,8 @@
        OPT_DELETESMSFOLDER,
        OPT_CREATESMSFOLDER,
        OPT_LISTNETWORKS,
-       OPT_GETNETWORKINFO
+       OPT_GETNETWORKINFO,
+       OPT_GETLOCKSINFO
 } opt_index;
 
 static char *bindir;     /* Binaries directory from .gnokiirc file - not used 
here yet */
@@ -318,6 +319,7 @@
                     "                 [{--number|-n} number]\n"
                     "          gnokii --listnetworks\n"
                     "          gnokii --getnetworkinfo\n"
+                    "          gnokii --getlocksinfo\n"
                ));
 #ifdef SECURITY
        fprintf(f, _("          gnokii --entersecuritycode PIN|PIN2|PUK|PUK2\n"
@@ -4277,6 +4279,30 @@
        return 0;
 }
 
+static int getlocksinfo(void)
+{
+       gn_locks_info locks_info[4];
+       char *locks_names[] = {"MCC+MNC", "GID1", "GID2", "MSIN"};
+       int i;
+
+       gn_data_clear(&data);
+       data.locks_info = locks_info;
+
+       if (gn_sm_functions(GN_OP_GetLocksInfo, &data, &state) != GN_ERR_NONE) {
+               return -1;
+       }
+
+       for (i = 0; i < 4; i++) {
+               fprintf(stdout, _("%7s : %10s, %7s, %6s, counter %d\n"),
+                       locks_names[i],
+                       locks_info[i].data,
+                       locks_info[i].userlock ? "user" : "factory",
+                       locks_info[i].closed ? "CLOSED" : "open",
+                       locks_info[i].counter);
+       }
+       return 0;
+}
+
 /* This is a "convenience" function to allow quick test of new API stuff which
    doesn't warrant a "proper" command line function. */
 #ifndef WIN32
@@ -4524,6 +4550,9 @@
                /* Get network info */
                { "getnetworkinfo",     no_argument,       NULL, 
OPT_GETNETWORKINFO },
 
+               /* Get (sim)lock info */
+               { "getlocksinfo",       no_argument,       NULL, 
OPT_GETLOCKSINFO },
+
                { 0, 0, 0, 0},
        };
 
@@ -4818,6 +4847,9 @@
                case OPT_GETNETWORKINFO:
                        rc = getnetworkinfo();
                        break;
+               case OPT_GETLOCKSINFO:
+                       rc = getlocksinfo();
+                       break;
 #ifndef WIN32
                case OPT_FOOGLE:
                        rc = foogle(nargv);
diff -Nru /home/bertrik/gnokii.clean/include/gsm-common.h 
/home/bertrik/gnokii/include/gsm-common.h
--- /home/bertrik/gnokii.clean/include/gsm-common.h     2002-12-23 
13:34:11.000000000 +0100
+++ /home/bertrik/gnokii/include/gsm-common.h   2003-01-04 18:46:52.000000000 
+0100
@@ -590,4 +590,11 @@
        char screen[50];
 } gn_netmonitor;
 
+typedef struct {
+       bool  userlock;         /* TRUE = user lock, FALSE = factory lock */
+       bool  closed;
+       char  data[12];
+       int   counter;
+} gn_locks_info;
+
 #endif /* _gnokii_gsm_common_h */
diff -Nru /home/bertrik/gnokii.clean/include/gsm-data.h 
/home/bertrik/gnokii/include/gsm-data.h
--- /home/bertrik/gnokii.clean/include/gsm-data.h       2003-01-03 
21:59:29.000000000 +0100
+++ /home/bertrik/gnokii/include/gsm-data.h     2003-01-04 18:42:53.000000000 
+0100
@@ -96,6 +96,7 @@
        gn_key_code key_code;
        unsigned char character;
        gn_phone_model *phone;
+       gn_locks_info *locks_info;
 } gn_data;
 
 /* 
@@ -215,6 +216,7 @@
        GN_OP_GetWAPSetting,
        GN_OP_ActivateWAPSetting,
        GN_OP_WriteWAPSetting,
+       GN_OP_GetLocksInfo,
        GN_OP_Max,      /* don't append anything after this entry */
 } gn_operation;
 


reply via email to

[Prev in Thread] Current Thread [Next in Thread]