forked from DerArtem/huaweigeneric-ril-old
-
Notifications
You must be signed in to change notification settings - Fork 0
/
huaweigeneric-ril.c
4710 lines (3852 loc) · 114 KB
/
huaweigeneric-ril.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* //device/system/htcgeneric-ril/htcgeneric-ril.c
**
** Copyright 2006, The Android Open Source Project
**
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at
**
** http://www.apache.org/licenses/LICENSE-2.0
**
** Unless required by applicable law or agreed to in writing, software
** distributed under the License is distributed on an "AS IS" BASIS,
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
** See the License for the specific language governing permissions and
** limitations under the License.
*/
#include <telephony/ril.h>
#include <stdio.h>
#include <assert.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <pthread.h>
#include <alloca.h>
#include "atchannel.h"
#include "at_tok.h"
#include "misc.h"
#include "gsm.h"
#include <getopt.h>
#include <sys/socket.h>
#include <cutils/sockets.h>
#include <termios.h>
#include <cutils/properties.h>
#define LOG_NDEBUG 0
#define LOG_TAG "RIL"
#include <utils/Log.h>
/* backwards compatibility for pre-JB */
#ifndef ALOGD
#define ALOGD LOGD
#define ALOGE LOGE
#define ALOGI LOGI
#endif
#define MAX_AT_RESPONSE 0x1000
/* pathname returned from RIL_REQUEST_SETUP_DATA_CALL / RIL_REQUEST_SETUP_DEFAULT_PDP */
#define PPP_TTY_PATH "ppp0"
#ifdef USE_TI_COMMANDS
// Enable workaround for bug in (TI-based) HTC stack
// 1) Make incoming call, do not answer
// 2) Hangup remote end
// Expected: call should disappear from CLCC line
// Actual: Call shows as "ACTIVE" before disappearing
#define WORKAROUND_ERRONEOUS_ANSWER 1
// Some varients of the TI stack do not support the +CGEV unsolicited
// response. However, they seem to send an unsolicited +CME ERROR: 150
#define WORKAROUND_FAKE_CGEV 1
#endif
typedef enum {
SIM_ABSENT = 0,
SIM_NOT_READY = 1,
SIM_READY = 2, /* SIM_READY means the radio state is RADIO_STATE_SIM_READY */
SIM_PIN = 3,
SIM_PUK = 4,
SIM_NETWORK_PERSONALIZATION = 5
} SIM_Status;
static void onRequest (int request, void *data, size_t datalen, RIL_Token t);
static RIL_RadioState currentState();
static int onSupports (int requestCode);
static void onCancel (RIL_Token t);
static const char *getVersion();
static int isRadioOn();
static SIM_Status getSIMStatus();
static int getCardStatus(RIL_CardStatus_v6 **pp_card_status);
static void freeCardStatus(RIL_CardStatus_v6 *p_card_status);
static void onDataCallListChanged(void *param);
static int killConn(char * cid);
extern const char * requestToString(int request);
/*** Static Variables ***/
static const RIL_RadioFunctions s_callbacks = {
RIL_VERSION,
onRequest,
currentState,
onSupports,
onCancel,
getVersion
};
#ifdef RIL_SHLIB
static const struct RIL_Env *s_rilenv;
#define RIL_onRequestComplete(t, e, response, responselen) s_rilenv->OnRequestComplete(t,e, response, responselen)
#define RIL_onUnsolicitedResponse(a,b,c) s_rilenv->OnUnsolicitedResponse(a,b,c)
#define RIL_requestTimedCallback(a,b,c) s_rilenv->RequestTimedCallback(a,b,c)
#endif
static RIL_RadioState sState = RADIO_STATE_UNAVAILABLE;
static pthread_mutex_t s_state_mutex = PTHREAD_MUTEX_INITIALIZER;
static pthread_cond_t s_state_cond = PTHREAD_COND_INITIALIZER;
static int s_port = -1;
static const char * s_device_path = NULL;
static int s_device_socket = 0;
/* trigger change to this with s_state_cond */
static int s_closed = 0;
static int sFD; /* file desc of AT channel */
static char sATBuffer[MAX_AT_RESPONSE+1];
static char *sATBufferCur = NULL;
static char *sNITZtime = NULL;
static const struct timeval TIMEVAL_SIMPOLL = {1,0};
static const struct timeval TIMEVAL_CALLSTATEPOLL = {0,500000};
static const struct timeval TIMEVAL_0 = {0,0};
#ifdef WORKAROUND_ERRONEOUS_ANSWER
// Max number of times we'll try to repoll when we think
// we have a AT+CLCC race condition
#define REPOLL_CALLS_COUNT_MAX 4
// Line index that was incoming or waiting at last poll, or -1 for none
static int s_incomingOrWaitingLine = -1;
// Number of times we've asked for a repoll of AT+CLCC
static int s_repollCallsCount = 0;
// Should we expect a call to be answered in the next CLCC?
static int s_expectAnswer = 0;
#endif /* WORKAROUND_ERRONEOUS_ANSWER */
static void pollSIMState (void *param);
static void setRadioState(RIL_RadioState newState);
static int isgsm=0;
static char erisystem[50];
static char *callwaiting_num;
static int countValidCalls=0;
static int wait_for_property(const char *name, const char *desired_value, int maxwait)
{
char value[PROPERTY_VALUE_MAX] = {'\0'};
int maxnaps = maxwait / 1;
if (maxnaps < 1) {
maxnaps = 1;
}
while (maxnaps-- > 0) {
usleep(1000000);
if (property_get(name, value, NULL)) {
if (desired_value == NULL ||
strcmp(value, desired_value) == 0) {
return 0;
}
}
}
return -ETIMEDOUT; /* failure */
}
#define PPPD_SERVICE "pppd_gprs"
static int pppd_start(const char *user, const char *pass)
{
char *cmd = NULL;
asprintf(&cmd, PPPD_SERVICE ":%s %s", user ? "name" : "", pass ? pass : "");
property_set("ctl.start", cmd);
free(cmd);
return wait_for_property("init.svc." PPPD_SERVICE, "running", 10);
}
static int is_pppd_running(void)
{
char value[PROPERTY_VALUE_MAX] = {'\0'};
property_get("init.svc." PPPD_SERVICE, value, NULL);
return strcmp(value, "running") == 0;
}
static int pppd_stop(void)
{
property_set("ctl.stop", PPPD_SERVICE);
return wait_for_property("init.svc." PPPD_SERVICE, "stopped", 10);
}
static void handle_cdma_ccwa (const char *s)
{
int err;
char *line, *tmp;
line = tmp = strdup(s);
err = at_tok_start(&tmp);
if (err)
return;
err = at_tok_nextstr(&tmp, &callwaiting_num);
if (err)
return;
callwaiting_num = strdup(callwaiting_num);
free(line);
ALOGE("successfully set callwaiting_numn");
}
extern char** cdma_to_gsmpdu(const char *);
extern char* gsm_to_cdmapdu(const char *);
extern int hex2int(const char);
static void HexStr_to_DecInt(char *strings, unsigned int *ints)
{
int i = 0;
int j = strlen(strings);
int k = 0;
for(i = 0, k = 0; i < j; i += 2, k++)
{
printf("%d, %d\n", i, k);
if(strings[i] <= 57){
*(ints + k) += (unsigned int)((strings[i] - 48) * 16);
}
else{
*(ints+k) += (unsigned int)(((strings[i] - 97) + 10) * 16);
}
if(strings[i+1] <= 57){
*(ints+k) += (unsigned int)(strings[i+1] - 48);
}
else{
*(ints+k) += (unsigned int)((strings[i+1] - 97) + 10);
}
}
}
static int clccStateToRILState(int state, RIL_CallState *p_state)
{
switch(state) {
case 0: *p_state = RIL_CALL_ACTIVE; return 0;
case 1: *p_state = RIL_CALL_HOLDING; return 0;
case 2: *p_state = RIL_CALL_DIALING; return 0;
case 3: *p_state = RIL_CALL_ALERTING; return 0;
case 4: *p_state = RIL_CALL_INCOMING; return 0;
case 5: *p_state = RIL_CALL_WAITING; return 0;
default: return -1;
}
}
static const char* networkStatusToRilString(int state)
{
switch(state){
case 0: return("unknown"); break;
case 1: return("available"); break;
case 2: return("current"); break;
case 3: return("forbidden"); break;
default: return NULL;
}
}
// some phone functions are controlled by msm_proc_comm through /sys
/*
void writesys(char *name, char *val) {
FILE *fout;
char filename[256];
strcpy(filename,"/sys/class/vogue_hw/");
strcat(filename,name);
fout=fopen(filename,"w");
if(!fout) return;
fprintf(fout,val);
fclose(fout);
}
*/
/**
* Note: directly modified line and has *p_call point directly into
* modified line
*/
static int callFromCLCCLine(char *line, RIL_Call *p_call)
{
//+CLCC: 1,0,2,0,0,\"+18005551212\",145
// index,isMT,state,mode,isMpty(,number,TOA)?
int err;
int state;
int mode;
err = at_tok_start(&line);
if (err < 0) goto error;
err = at_tok_nextint(&line, &(p_call->index));
if (err < 0) goto error;
err = at_tok_nextbool(&line, &(p_call->isMT));
if (err < 0) goto error;
err = at_tok_nextint(&line, &state);
if (err < 0) goto error;
err = clccStateToRILState(state, &(p_call->state));
if (err < 0) goto error;
err = at_tok_nextint(&line, &mode);
if (err < 0) goto error;
p_call->isVoice = (mode == 0);
err = at_tok_nextbool(&line, &(p_call->isMpty));
if (err < 0) goto error;
if (at_tok_hasmore(&line)) {
err = at_tok_nextstr(&line, &(p_call->number));
/* tolerate null here */
if (err < 0) return 0;
// Some lame implementations return strings
// like "NOT AVAILABLE" in the CLCC line
if (p_call->number != NULL
&& 0 == strspn(p_call->number, "+0123456789")
) {
p_call->number = NULL;
}
err = at_tok_nextint(&line, &p_call->toa);
if (err < 0) goto error;
}
return 0;
error:
ALOGE("invalid CLCC line\n");
return -1;
}
//returns the call number of the active data call, or -1 if no active call
static int dataCallNum()
{
int err;
ATResponse *p_response;
ATLine *p_cur;
int countCalls;
RIL_Call *p_call;
int i;
int callNumber = -1;
if(currentState() != RADIO_STATE_SIM_READY){
return -1;
}
err = at_send_command_multiline ("AT+CLCC", "+CLCC:", &p_response);
if (err != 0 || p_response->success == 0) {
return -1;
}
/* count the calls */
for (countCalls = 0, p_cur = p_response->p_intermediates
; p_cur != NULL
; p_cur = p_cur->p_next
) {
countCalls++;
}
p_call = (RIL_Call *)alloca(sizeof(RIL_Call));
memset (p_call, 0, sizeof(RIL_Call));
for (i = 0, p_cur = p_response->p_intermediates
; p_cur != NULL
; p_cur = p_cur->p_next
) {
err = callFromCLCCLine(p_cur->line, p_call);
if (err != 0) {
continue;
}
if(p_call[0].isVoice == 0) // only count data calls
{
callNumber = i;
}
}
return callNumber;
}
/** do post-AT+CFUN=1 initialization */
static void onRadioPowerOn()
{
#ifdef USE_TI_COMMANDS
/* Must be after CFUN=1 */
/* TI specific -- notifications for CPHS things such */
/* as CPHS message waiting indicator */
at_send_command("AT%CPHS=1", NULL);
/* TI specific -- enable NITZ unsol notifs */
at_send_command("AT%CTZV=1", NULL);
#endif
if(isgsm)
{
ALOGD("onRadioPowerOn1");
sleep(10);
ALOGD("onRadioPowerOn2");
at_send_command("ATE0", NULL);
at_send_command("AT+CLIP=1", NULL);
at_send_command("AT+CLIR=0", NULL);
//at_send_command("AT+CPPP=2", NULL);
//at_send_command("AT+HTCNV=1,12,6", NULL);
/*enable ENS mode, okay to fail */
// at_send_command("AT+HTCENS=1", NULL);
// at_send_command("AT+HSDPA=1", NULL);
//at_send_command("AT+HTCAGPS=5", NULL);
at_send_command("AT", NULL);
//at_send_command("AT+ODEN=112", NULL);
//at_send_command("AT+ODEN=911", NULL);
// at_send_command("AT+ALS=4294967295", NULL);
}
pollSIMState(NULL);
}
/** do post- SIM ready initialization */
static void onSIMReady()
{
/* Common initialization commands */
/* Network registration */
at_send_command("AT+COPS=0", NULL);
if(isgsm) {
/* Preferred RAT - UMTS Dualmode */
// at_send_command("AT+XRAT=1,2", NULL);
//debug what type of sim is it?
//at_send_command("AT+SIMTYPE", NULL);
/*
* Always send SMS messages directly to the TE
*
* mode = 1 // discard when link is reserved (link should never be
* reserved)
* mt = 2 // most messages routed to TE
* bm = 2 // new cell BM's routed to TE
* ds = 1 // Status reports routed to TE
* bfr = 1 // flush buffer
*/
at_send_command("AT+CNMI=1,2,2,1,1", NULL);
at_send_command("AT+CSCB=1", NULL);
/* Enable +CGEV GPRS event notifications, but don't buffer */
// at_send_command("AT+CGEREP=1,0", NULL);
/* Enable NITZ reporting */
at_send_command("AT+CTZU=1", NULL);
at_send_command("AT+CTZR=1", NULL);
//at_send_command("AT+HTCCTZR=1", NULL);
/* Enable unsolizited RSSI reporting */
//at_send_command("AT@HTCCSQ=1", NULL);
at_send_command_singleline("AT+CSMS=1", "+CSMS:", NULL);
} else {
//at_send_command("AT+HTC_GPSONE=4", NULL);
at_send_command("AT+CLVL=5", NULL);
at_send_command("AT+CLVL=4", NULL);
}
}
static void requestRadioPower(void *data, size_t datalen, RIL_Token t)
{
int onOff;
int err;
ATResponse *p_response = NULL;
assert (datalen >= sizeof(int *));
onOff = ((int *)data)[0];
/*
if (onOff == 0 && sState != RADIO_STATE_OFF) {
if(isgsm)
err = at_send_command("AT+CFUN=0", &p_response);
else
err = at_send_command("AT+CFUN=66", &p_response);
if (err < 0 || p_response->success == 0) goto error;
setRadioState(RADIO_STATE_OFF);
} else if (onOff > 0 && sState == RADIO_STATE_OFF) {
err = at_send_command("AT+CFUN=1", &p_response);
if (err < 0|| p_response->success == 0) {
// Some stacks return an error when there is no SIM,
// but they really turn the RF portion on
// So, if we get an error, let's check to see if it
// turned on anyway
if (isRadioOn() != 1) {
goto error;
}
}
setRadioState(RADIO_STATE_SIM_NOT_READY);
}
*/
at_response_free(p_response);
RIL_onRequestComplete(t, RIL_E_SUCCESS, NULL, 0);
return;
error:
at_response_free(p_response);
RIL_onRequestComplete(t, RIL_E_GENERIC_FAILURE, NULL, 0);
}
static void requestOrSendDataCallList(RIL_Token *t);
static void onDataCallListChanged(void *param)
{
requestOrSendDataCallList(NULL);
}
static void requestDataCallList(void *data, size_t datalen, RIL_Token t)
{
requestOrSendDataCallList(&t);
}
static void requestOrSendDataCallList(RIL_Token *t)
{
ATResponse *p_response;
ATLine *p_cur;
RIL_Data_Call_Response_v6 *responses;
int err;
char status[1];
int fd;
int pppConnected = 0;
int n = 0;
char *out;
if (isgsm) {
err = at_send_command_multiline ("AT+CGACT?", "+CGACT:", &p_response);
if (err != 0 || p_response->success == 0) {
if (t != NULL)
RIL_onRequestComplete(*t, RIL_E_GENERIC_FAILURE, NULL, 0);
else
RIL_onUnsolicitedResponse(RIL_UNSOL_DATA_CALL_LIST_CHANGED,
NULL, 0);
return;
}
for (p_cur = p_response->p_intermediates; p_cur != NULL;
p_cur = p_cur->p_next)
n++;
responses = alloca(n * sizeof(RIL_Data_Call_Response_v6));
int i;
for (i = 0; i < n; i++) {
responses[i].status = -1;
responses[i].suggestedRetryTime = -1;
responses[i].cid = -1;
responses[i].active = -1;
responses[i].type = "";
responses[i].ifname = "";
responses[i].addresses = "";
responses[i].dnses = "";
responses[i].gateways = "";
}
RIL_Data_Call_Response_v6 *response = responses;
for (p_cur = p_response->p_intermediates; p_cur != NULL;
p_cur = p_cur->p_next) {
char *line = p_cur->line;
err = at_tok_start(&line);
if (err < 0)
goto error;
err = at_tok_nextint(&line, &response->cid);
if (err < 0)
goto error;
err = at_tok_nextint(&line, &response->active);
if (err < 0)
goto error;
response++;
}
at_response_free(p_response);
err = at_send_command_multiline ("AT+CGDCONT?", "+CGDCONT:", &p_response);
if (err != 0 || p_response->success == 0) {
if (t != NULL)
RIL_onRequestComplete(*t, RIL_E_GENERIC_FAILURE, NULL, 0);
else
RIL_onUnsolicitedResponse(RIL_UNSOL_DATA_CALL_LIST_CHANGED,
NULL, 0);
return;
}
for (p_cur = p_response->p_intermediates; p_cur != NULL;
p_cur = p_cur->p_next) {
char *line = p_cur->line;
int cid;
err = at_tok_start(&line);
if (err < 0)
goto error;
err = at_tok_nextint(&line, &cid);
if (err < 0)
goto error;
for (i = 0; i < n; i++) {
if (responses[i].cid == cid)
break;
}
if (i >= n) {
/* details for a context we didn't hear about in the last request */
continue;
}
// Assume no error
responses[i].status = 0;
// type
err = at_tok_nextstr(&line, &out);
if (err < 0)
goto error;
responses[i].type = alloca(strlen(out) + 1);
strcpy(responses[i].type, out);
// APN ignored for v5
err = at_tok_nextstr(&line, &out);
if (err < 0)
goto error;
responses[i].ifname = alloca(strlen(PPP_TTY_PATH) + 1);
strcpy(responses[i].ifname, PPP_TTY_PATH);
err = at_tok_nextstr(&line, &out);
if (err < 0)
goto error;
responses[i].addresses = alloca(strlen(out) + 1);
strcpy(responses[i].addresses, out);
}
at_response_free(p_response);
} else {
//CDMA
n = 1;
responses = alloca(sizeof(RIL_Data_Call_Response_v6));
responses[0].cid = 1;
if (dataCallNum() >= 0)
responses[0].active = 1;
else
responses[0].active = 0;
responses[0].suggestedRetryTime = -1;
responses[0].type = "";
responses[0].ifname = "";
responses[0].addresses = "";
responses[0].dnses = "";
responses[0].gateways = "";
}
// make sure pppd is still running, invalidate datacall if it isn't
if (!is_pppd_running()) {
responses[0].active = 0;
}
if (t != NULL)
RIL_onRequestComplete(*t, RIL_E_SUCCESS, responses,
n * sizeof(RIL_Data_Call_Response_v6));
else
RIL_onUnsolicitedResponse(RIL_UNSOL_DATA_CALL_LIST_CHANGED,
responses,
n * sizeof(RIL_Data_Call_Response_v6));
return;
error:
if (t != NULL)
RIL_onRequestComplete(*t, RIL_E_GENERIC_FAILURE, NULL, 0);
else
RIL_onUnsolicitedResponse(RIL_UNSOL_DATA_CALL_LIST_CHANGED,
NULL, 0);
at_response_free(p_response);
}
static void requestBasebandVersion(void *data, size_t datalen, RIL_Token t)
{
int err;
ATResponse *p_response = NULL;
char * response = NULL;
char* line = NULL;
if (isgsm) {
err = at_send_command_singleline("AT+CGMM", "", &p_response);
if (err != 0) goto error;
line = p_response->p_intermediates->line;
response = (char *)alloca(sizeof(char *));
err = at_tok_nextstr(&line, &response);
if (err < 0) goto error;
RIL_onRequestComplete(t, RIL_E_SUCCESS, response, sizeof(char *));
at_response_free(p_response);
} else {
RIL_onRequestComplete(t, RIL_E_REQUEST_NOT_SUPPORTED, NULL, 0);
}
return;
error:
at_response_free(p_response);
ALOGE("ERROR: requestBasebandVersion failed\n");
RIL_onRequestComplete(t, RIL_E_GENERIC_FAILURE, NULL, 0);
}
static void requestQueryNetworkSelectionMode(
void *data, size_t datalen, RIL_Token t)
{
int err;
ATResponse *p_response = NULL;
int response = 0;
char *line;
if(isgsm) { //this command conflicts with the network status command
err = at_send_command_singleline("AT+COPS?", "+COPS:", &p_response);
if (err < 0 || p_response->success == 0) {
goto error;
}
line = p_response->p_intermediates->line;
err = at_tok_start(&line);
if (err < 0) {
goto error;
}
err = at_tok_nextint(&line, &response);
if (err < 0) {
goto error;
}
}
RIL_onRequestComplete(t, RIL_E_SUCCESS, &response, sizeof(int));
at_response_free(p_response);
return;
error:
at_response_free(p_response);
ALOGE("requestQueryNetworkSelectionMode must never return error when radio is on");
RIL_onRequestComplete(t, RIL_E_GENERIC_FAILURE, NULL, 0);
}
static void requestQueryAvailableNetworks(void *data, size_t datalen, RIL_Token t)
{
/* We expect an answer on the following form:
+COPS: (2,"AT&T","AT&T","310410",0),(1,"T-Mobile ","TMO","310260",0)
*/
int err, operators, i, skip, status;
ATResponse *p_response = NULL;
char * c_skip, *line, *p = NULL;
char ** response = NULL;
err = at_send_command_singleline("AT+COPS=?", "+COPS:", &p_response);
if (err != 0) goto error;
line = p_response->p_intermediates->line;
err = at_tok_start(&line);
if (err < 0) goto error;
/* Count number of '(' in the +COPS response to get number of operators*/
operators = 0;
for (p = line ; *p != '\0' ;p++) {
if (*p == '(') operators++;
}
response = (char **)alloca(operators * 4 * sizeof(char *));
for (i = 0 ; i < operators ; i++ )
{
err = at_tok_nextstr(&line, &c_skip);
if (err < 0) goto error;
if (strcmp(c_skip,"") == 0)
{
operators = i;
continue;
}
status = atoi(&c_skip[1]);
response[i*4+3] = (char*)networkStatusToRilString(status);
err = at_tok_nextstr(&line, &(response[i*4+0]));
if (err < 0) goto error;
err = at_tok_nextstr(&line, &(response[i*4+1]));
if (err < 0) goto error;
err = at_tok_nextstr(&line, &(response[i*4+2]));
if (err < 0) goto error;
err = at_tok_nextstr(&line, &c_skip);
if (err < 0) goto error;
}
RIL_onRequestComplete(t, RIL_E_SUCCESS, response, (operators * 4 * sizeof(char *)));
at_response_free(p_response);
return;
error:
at_response_free(p_response);
ALOGE("ERROR - requestQueryAvailableNetworks() failed");
RIL_onRequestComplete(t, RIL_E_GENERIC_FAILURE, NULL, 0);
}
static void requestGetPreferredNetworkType(void *data, size_t datalen, RIL_Token t)
{
int err;
ATResponse *p_response = NULL;
int response = 0;
char *line;
if(isgsm)
{
/*
err = at_send_command_singleline("AT+CGAATT?", "+CGAATT:", &p_response);
if (err < 0 || p_response->success == 0) {
goto error;
}
line = p_response->p_intermediates->line;
err = at_tok_start(&line);
if (err < 0) {
goto error;
}
// Get third int in response
err = at_tok_nextint(&line, &response);
if (err < 0) {
goto error;
}
err = at_tok_nextint(&line, &response);
if (err < 0) {
goto error;
}
err = at_tok_nextint(&line, &response);
if (err < 0) {
goto error;
}
*/
response = 0;
RIL_onRequestComplete(t, RIL_E_SUCCESS, &response, sizeof(int));
at_response_free(p_response);
return;
}
ALOGE("ERROR: requestGetPreferredNetworkType() failed - modem does not support command\n");
RIL_onRequestComplete(t, RIL_E_GENERIC_FAILURE, NULL, 0);
return;
error:
at_response_free(p_response);
ALOGE("ERROR: requestGetPreferredNetworkType() failed\n");
RIL_onRequestComplete(t, RIL_E_GENERIC_FAILURE, NULL, 0);
}
static void requestSetPreferredNetworkType(void *data, size_t datalen, RIL_Token t)
{
int err, rat;
ATResponse *p_response = NULL;
char * cmd = NULL;
const char *at_rat = NULL;
if(isgsm)
{
RIL_onRequestComplete(t, RIL_E_SUCCESS, NULL, sizeof(int));
return;
assert (datalen >= sizeof(int *));
rat = ((int *)data)[0];
switch (rat) {
case 1: at_rat = "2,1,1"; break; /* GSM only */
case 2: at_rat = "2,1,2"; break; /* WsCDMA only */
default: at_rat = "2,1,0"; break; /* Dual Mode - WCDMA preferred*/
}
err = at_send_command("AT+BANDSET=0", NULL);
if (err < 0) goto error;
asprintf(&cmd, "AT+CGAATT=%s", at_rat);
err = at_send_command(cmd, &p_response);
free(cmd);
if (err < 0|| p_response->success == 0) {
goto error;
}
/* Trigger autoregister */
err = at_send_command("AT+COPS=0", NULL);
if (err < 0) goto error;
RIL_onRequestComplete(t, RIL_E_SUCCESS, NULL, sizeof(int));
at_response_free(p_response);
return;
}
ALOGE("ERROR: requestSetPreferredNetworkType() failed - command not supported by modem\n");
RIL_onRequestComplete(t, RIL_E_GENERIC_FAILURE, NULL, 0);
return;
error:
at_response_free(p_response);
ALOGE("ERROR: requestSetPreferredNetworkType() failed\n");
RIL_onRequestComplete(t, RIL_E_GENERIC_FAILURE, NULL, 0);
}
static void requestQueryFacilityLock(void *data, size_t datalen, RIL_Token t)
{
int err, rat, response;
ATResponse *p_response = NULL;
char * cmd = NULL;
char * line = NULL;
char * facility_string = NULL;
char * facility_password = NULL;
char * facility_class = NULL;
ALOGD("FACILITY");
assert (datalen >= (3 * sizeof(char **)));
facility_string = ((char **)data)[0];
facility_password = ((char **)data)[1];
facility_class = ((char **)data)[2];
//asprintf(&cmd, "AT+CLCK=\"%s\",2,\"%s\",%s", facility_string, facility_password, facility_class);
asprintf(&cmd, "AT+CLCK=\"%s\",2,%s,%s", facility_string, facility_password, facility_class);
err = at_send_command_singleline(cmd,"+CLCK:", &p_response);
free(cmd);
if (err < 0 || p_response->success == 0){
goto error;
}
line = p_response->p_intermediates->line;
err = at_tok_start(&line);
if (err < 0) {
goto error;
}
err = at_tok_nextint(&line, &response);
if (err < 0) {
goto error;
}
RIL_onRequestComplete(t, RIL_E_SUCCESS, &response, sizeof(int));
at_response_free(p_response);
return;
error:
at_response_free(p_response);
ALOGE("ERROR: requestQueryFacilityLock() failed\n");
RIL_onRequestComplete(t, RIL_E_GENERIC_FAILURE, NULL, 0);
}
static void sendCallStateChanged(void *param)
{
RIL_onUnsolicitedResponse (
RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED,
NULL, 0);
}
static void requestGetCurrentCalls(void *data, size_t datalen, RIL_Token t)
{
int err,fd;
ATResponse *p_response;
ATLine *p_cur;