gnokii-users
[Top][All Lists]
Advanced

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

Re: [patch] unsigned ints for cell_id and LAC in gn_network_info struct


From: Bertrik Sikken
Subject: Re: [patch] unsigned ints for cell_id and LAC in gn_network_info structure
Date: Thu, 23 Jan 2003 00:22:49 +0100
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.2.1) Gecko/20021130

Pawel Kot wrote:

Hi Bertrik,

Thanks for the patch. One comment on it.

You define:
+       unsigned int cell_id;
+       unsigned int LAC;
and we have
unsigned char message[];
Now you do the assignments:
+         data->network_info->cell_id = (message[10] << 8) + message[11];
+         data->network_info->LAC = (message[12] << 8) + message[13];
+         data->network_info->cell_id = (blockstart[6] << 8) + blockstart[7];
+         data->network_info->LAC = (blockstart[2] << 8) + blockstart[3];
+         data->network_info->cell_id = (blockstart[4] << 8) + blockstart[5];
+         data->network_info->LAC = (blockstart[6] << 8) + blockstart[7];
blockstart[] is also unsigned char array.

Which is unfortunately incorrect what we recently experienced.

(blockstart[N] << 8) and (message[N] << 8) are also of the unsigned char
type! So it is not what we wanted. This is recently discivered by me and
not fixed yet all over gnokii.

The correct form would be:
LAC = message[12] * 256 + message[13]
or
LAC = (((unsigned int)message[12]) << 8) + message[13]

Would you mind to correct the patch?

Ok, attached is a corrected patch.
It implements the LAC = message[12] * 256 + message[13] solution.

Regards,
Bertrik


diff -Nru --exclude CVS gnokii.clean/common/phones/nk6100.c 
gnokii/common/phones/nk6100.c
--- gnokii.clean/common/phones/nk6100.c 2003-01-22 19:11:35.000000000 +0100
+++ gnokii/common/phones/nk6100.c       2003-01-23 00:11:07.000000000 +0100
@@ -1679,10 +1679,8 @@
        /* Network info */
        case 0x71:
                if (data->network_info) {
-                       data->network_info->cell_id[0] = message[10];
-                       data->network_info->cell_id[1] = message[11];
-                       data->network_info->LAC[0] = message[12];
-                       data->network_info->LAC[1] = message[13];
+                       data->network_info->cell_id = message[10] * 256 + 
message[11];
+                       data->network_info->LAC = message[12] * 256 + 
message[13];
                        data->network_info->network_code[0] = '0' + 
(message[14] & 0x0f);
                        data->network_info->network_code[1] = '0' + 
(message[14] >> 4);
                        data->network_info->network_code[2] = '0' + 
(message[15] & 0x0f);
diff -Nru --exclude CVS gnokii.clean/common/phones/nk6510.c 
gnokii/common/phones/nk6510.c
--- gnokii.clean/common/phones/nk6510.c 2003-01-22 19:11:36.000000000 +0100
+++ gnokii/common/phones/nk6510.c       2003-01-23 00:11:30.000000000 +0100
@@ -2225,10 +2225,8 @@
                        case 0x09:  /* Operator details */
                                /* Network code is stored as 0xBA 0xXC 0xED 
("ABC DE"). */
                                if (data->network_info) {
-                                       data->network_info->cell_id[0] = 
blockstart[6];
-                                       data->network_info->cell_id[1] = 
blockstart[7];
-                                       data->network_info->LAC[0] = 
blockstart[2];
-                                       data->network_info->LAC[1] = 
blockstart[3];
+                                       data->network_info->cell_id = 
blockstart[6] * 256 + blockstart[7];
+                                       data->network_info->LAC = blockstart[2] 
* 256 + blockstart[3];
                                        data->network_info->network_code[0] = 
'0' + (blockstart[8] & 0x0f);
                                        data->network_info->network_code[1] = 
'0' + (blockstart[8] >> 4);
                                        data->network_info->network_code[2] = 
'0' + (blockstart[9] & 0x0f);
diff -Nru --exclude CVS gnokii.clean/common/phones/nk7110.c 
gnokii/common/phones/nk7110.c
--- gnokii.clean/common/phones/nk7110.c 2003-01-22 19:11:36.000000000 +0100
+++ gnokii/common/phones/nk7110.c       2003-01-23 00:11:50.000000000 +0100
@@ -470,10 +470,8 @@
                                /* Network code is stored as 0xBA 0xXC 0xED 
("ABC DE"). */
                                if (data->network_info) {
                                        /* Is this correct? */
-                                       data->network_info->cell_id[0] = 
blockstart[4];
-                                       data->network_info->cell_id[1] = 
blockstart[5];
-                                       data->network_info->LAC[0] = 
blockstart[6];
-                                       data->network_info->LAC[1] = 
blockstart[7];
+                                       data->network_info->cell_id = 
blockstart[4] * 256 + blockstart[5];
+                                       data->network_info->LAC = blockstart[6] 
* 256 + blockstart[7];
                                        data->network_info->network_code[0] = 
'0' + (blockstart[8] & 0x0f);
                                        data->network_info->network_code[1] = 
'0' + (blockstart[8] >> 4);
                                        data->network_info->network_code[2] = 
'0' + (blockstart[9] & 0x0f);
diff -Nru --exclude CVS gnokii.clean/gnokii/gnokii.c gnokii/gnokii/gnokii.c
--- gnokii.clean/gnokii/gnokii.c        2003-01-22 19:11:36.000000000 +0100
+++ gnokii/gnokii/gnokii.c      2003-01-22 19:18:11.000000000 +0100
@@ -2611,7 +2611,7 @@
                        fprintf(stdout, _("SMS Messages: Unread %d, Number 
%d\n"), smsstatus.unread, smsstatus.number);
 
                if (gn_sm_functions(GN_OP_GetNetworkInfo, &data, &state) == 
GN_ERR_NONE)
-                       fprintf(stdout, _("Network: %s (%s), LAC: %02x%02x, 
CellID: %02x%02x\n"), gn_network_name_get(networkinfo.network_code), 
gn_country_name_get(networkinfo.network_code), networkinfo.LAC[0], 
networkinfo.LAC[1], networkinfo.cell_id[0], networkinfo.cell_id[1]);
+                       fprintf(stdout, _("Network: %s (%s), LAC: %04x, CellID: 
%04x\n"), gn_network_name_get(networkinfo.network_code), 
gn_country_name_get(networkinfo.network_code), networkinfo.LAC, 
networkinfo.cell_id);
 
                for (i = 0; i < GN_CALL_MAX_PARALLEL; i++)
                        displaycall(i);
@@ -4269,7 +4269,6 @@
 {
        gn_network_info networkinfo;
        gn_data data;
-       int cid, lac;
        char country[4] = {0, 0, 0, 0};
 
        gn_data_clear(&data);
@@ -4279,16 +4278,14 @@
                return -1;
        }
 
-       cid = (networkinfo.cell_id[0] << 8) + networkinfo.cell_id[1];
-       lac = (networkinfo.LAC[0] << 8) + networkinfo.LAC[1];
        memcpy(country, networkinfo.network_code, 3);
 
        fprintf(stdout, _("Network      : %s (%s)\n"),
                        gn_network_name_get((char *)networkinfo.network_code),
                        gn_country_name_get((char *)country));
        fprintf(stdout, _("Network code : %s\n"), networkinfo.network_code);
-       fprintf(stdout, _("LAC          : %04x\n"), lac);
-       fprintf(stdout, _("Cell id      : %04x\n"), cid);
+       fprintf(stdout, _("LAC          : %04x\n"), networkinfo.LAC);
+       fprintf(stdout, _("Cell id      : %04x\n"), networkinfo.cell_id);
 
        return 0;
 }
diff -Nru --exclude CVS gnokii.clean/include/gsm-common.h 
gnokii/include/gsm-common.h
--- gnokii.clean/include/gsm-common.h   2003-01-22 19:11:36.000000000 +0100
+++ gnokii/include/gsm-common.h 2003-01-22 19:13:58.000000000 +0100
@@ -127,8 +127,8 @@
 /* This structure is used to get the current network status */
 typedef struct {
        char network_code[10];     /* GSM network code */
-       unsigned char cell_id[10]; /* CellID */
-       unsigned char LAC[10];     /* LAC */
+       unsigned int cell_id;
+       unsigned int LAC;
 } gn_network_info;
 
 /* Limits for sizing of array in gn_phonebook_entry. Individual handsets may

reply via email to

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