rjw | 1f88458 | 2022-01-06 17:20:42 +0800 | [diff] [blame^] | 1 | #include "common.h" |
| 2 | #include "lynq_common.h" |
| 3 | #include "lynq_data.h" |
| 4 | #include "lynq_network.h" |
| 5 | #include "stateManager/stateManager.h" |
| 6 | #include <string.h> |
| 7 | #include <stdlib.h> |
| 8 | #undef LOG_TAG |
| 9 | #define LOG_TAG "LYNQ_DATA" |
| 10 | #define DATA_CALL_LIST_MAX 10 |
| 11 | //ww add @2020.7.23 for add Data api |
| 12 | |
| 13 | void copyDataCallList(LYNQ_Data_Call_Response_v11 *newMsg,const RIL_Data_Call_Response_v11 oldMsg); |
| 14 | |
| 15 | RIL_Data_Call_Response_v11 * |
| 16 | checkParcelDataCallInfo(dataCallMsg* msg,int32_t token,int time) |
| 17 | { |
| 18 | int time_sim =time; |
| 19 | int num; |
| 20 | lynqQueue *node = NULL; |
| 21 | lynqQueue *temp =NULL; |
| 22 | RIL_Data_Call_Response_v11 *list = NULL; |
| 23 | while(time_sim--) |
| 24 | { |
| 25 | millli_sleep_with_restart(10); |
| 26 | temp=LynqQueueHead; |
| 27 | if(temp==NULL) |
| 28 | { |
| 29 | LYDBGLOG("Queue head is NULL, maybe malloc fail!"); |
| 30 | continue; |
| 31 | } |
| 32 | node = searchTokeninQueue(token, temp); |
| 33 | if(node ==NULL) |
| 34 | { |
| 35 | return NULL; |
| 36 | } |
| 37 | if(node->t_Errno!=RIL_E_SUCCESS) |
| 38 | { |
| 39 | LYDBGLOG("get data call list fail, the error code is %d",node->t_Errno); |
| 40 | msg->e=node->t_Errno; |
| 41 | return NULL; |
| 42 | } |
| 43 | else |
| 44 | { |
| 45 | node->parcel.setDataPosition(0); |
| 46 | if (node->parcel.dataAvail() > 0) |
| 47 | { |
| 48 | |
| 49 | node->parcel.readInt32(&num); |
| 50 | list = (RIL_Data_Call_Response_v11 *) calloc(1, sizeof(RIL_Data_Call_Response_v11) * num); |
| 51 | for(int i =0;i<num;i++) |
| 52 | { |
| 53 | node->parcel.readInt32(&list[i].status); |
| 54 | node->parcel.readInt32(&list[i].suggestedRetryTime); |
| 55 | node->parcel.readInt32(&list[i].cid); |
| 56 | node->parcel.readInt32(&list[i].active); |
| 57 | list[i].type = lynqStrdupReadString(node->parcel); |
| 58 | list[i].ifname = lynqStrdupReadString(node->parcel); |
| 59 | list[i].addresses = lynqStrdupReadString(node->parcel); |
| 60 | list[i].dnses = lynqStrdupReadString(node->parcel); |
| 61 | list[i].gateways = lynqStrdupReadString(node->parcel); |
| 62 | list[i].pcscf = lynqStrdupReadString(node->parcel); |
| 63 | node->parcel.readInt32(&list[i].mtu); |
| 64 | |
| 65 | } |
| 66 | msg->e=node->t_Errno; |
| 67 | msg->status = 0; |
| 68 | msg->num = num; |
| 69 | return list; |
| 70 | } |
| 71 | else |
| 72 | { |
| 73 | continue; |
| 74 | } |
| 75 | } |
| 76 | } |
| 77 | //printf("time_sim is %d\n",time_sim); |
| 78 | return NULL; |
| 79 | } |
| 80 | //enable_data.sh |
| 81 | int lynq_data_enable_data(int* PdnState) |
| 82 | { |
| 83 | char* mdata_apn[MAX_STRING_LEN]; |
| 84 | int param_num=8; |
| 85 | int res=-1; |
| 86 | int32_t token=0; |
| 87 | int32_t tokenTemp=0; |
| 88 | RIL_Data_Call_Response_v11 *list = NULL; |
| 89 | dataCallMsg msg; |
| 90 | msg.e=-1; |
| 91 | msg.num=-1; |
| 92 | msg.status=-1; |
| 93 | //lynq_query_network_selection_mode(); |
| 94 | token = lynqNoneParame("RIL_REQUEST_SETUP_DATA_CALL"); |
| 95 | millli_sleep_with_restart(150); |
| 96 | tokenTemp = lynqNoneParame("RIL_REQUEST_DATA_CALL_LIST"); |
| 97 | list = checkParcelDataCallInfo(&msg,tokenTemp,100); |
| 98 | if(list==NULL) |
| 99 | { |
| 100 | *PdnState = -1; |
| 101 | } |
| 102 | else |
| 103 | { |
| 104 | *PdnState = 0; |
| 105 | for (int i = 0; i < msg.num; i++) |
| 106 | { |
| 107 | free(list[i].type); |
| 108 | free(list[i].ifname); |
| 109 | free(list[i].addresses); |
| 110 | free(list[i].dnses); |
| 111 | free(list[i].gateways); |
| 112 | free(list[i].pcscf); |
| 113 | } |
| 114 | free(list); |
| 115 | } |
| 116 | lynqDeQueue(tokenTemp); |
| 117 | return token; |
| 118 | } |
| 119 | |
| 120 | //disable_data.sh |
| 121 | int lynq_data_dectivate_data_call(int *PdnState) |
| 122 | { |
| 123 | //printf("ww--lynq_data_dectivate_data_call--111\r\n"); |
| 124 | int32_t token=0; |
| 125 | int32_t tokenTemp=0; |
| 126 | RIL_Data_Call_Response_v11 *list = NULL; |
| 127 | dataCallMsg msg; |
| 128 | token = lynqNoneParame("RIL_REQUEST_DEACTIVATE_DATA_CALL"); |
| 129 | //millli_sleep_with_restart(100); |
| 130 | tokenTemp = lynqNoneParame("RIL_REQUEST_DATA_CALL_LIST"); |
| 131 | list = checkParcelDataCallInfo(&msg,tokenTemp,100); |
| 132 | if(list==NULL) |
| 133 | { |
| 134 | *PdnState = 0; |
| 135 | } |
| 136 | else |
| 137 | { |
| 138 | *PdnState = -1; |
| 139 | for (int i = 0; i < msg.num; i++) |
| 140 | { |
| 141 | free(list[i].type); |
| 142 | free(list[i].ifname); |
| 143 | free(list[i].addresses); |
| 144 | free(list[i].dnses); |
| 145 | free(list[i].gateways); |
| 146 | free(list[i].pcscf); |
| 147 | } |
| 148 | free(list); |
| 149 | } |
| 150 | lynqDeQueue(tokenTemp); |
| 151 | return token; |
| 152 | } |
| 153 | //the max of data call list number is 10; |
| 154 | int lynq_get_data_call_list(LYNQ_Data_Call_Response_v11 **dataCallList,const int listNum,int *realNum) |
| 155 | { |
| 156 | if(listNum>DATA_CALL_LIST_MAX) |
| 157 | { |
| 158 | LYDBGLOG("the list number is more than 10"); |
| 159 | return -1; |
| 160 | } |
| 161 | int32_t token=0; |
| 162 | RIL_Data_Call_Response_v11 *list = NULL; |
| 163 | dataCallMsg msg; |
| 164 | token = lynqNoneParame("RIL_REQUEST_DATA_CALL_LIST"); |
| 165 | list = checkParcelDataCallInfo(&msg,token,100); |
| 166 | if(list==NULL) |
| 167 | { |
| 168 | //dataCallList=NULL; |
| 169 | return token; |
| 170 | } |
| 171 | if(listNum<msg.num) |
| 172 | { |
| 173 | msg.num=listNum; |
| 174 | LYDBGLOG("listNum<msg.num!"); |
| 175 | } |
| 176 | *realNum=msg.num; |
| 177 | //dataCallList = (RIL_Data_Call_Response_v11 *) calloc(1, sizeof(RIL_Data_Call_Response_v11) * msg.num); |
| 178 | for(int i=0;i<msg.num;i++) |
| 179 | { |
| 180 | copyDataCallList(dataCallList[i], list[i]); |
| 181 | } |
| 182 | for (int i = 0; i < msg.num; i++) |
| 183 | { |
| 184 | free(list[i].type); |
| 185 | free(list[i].ifname); |
| 186 | free(list[i].addresses); |
| 187 | free(list[i].dnses); |
| 188 | free(list[i].gateways); |
| 189 | free(list[i].pcscf); |
| 190 | } |
| 191 | free(list); |
| 192 | lynqDeQueue(token); |
| 193 | /* |
| 194 | for(int i=0;i<msg.num;i++) |
| 195 | { |
| 196 | printf("test status is %d\n",dataCallList[i]->status); |
| 197 | printf("test suggested is %d\n",dataCallList[i]->suggestedRetryTime); |
| 198 | printf("test cid is %d\n",dataCallList[i]->cid); |
| 199 | printf("test active is %d\n",dataCallList[i]->active); |
| 200 | printf("test mtu is %d\n",dataCallList[i]->mtu); |
| 201 | printf("test string is %s\n",dataCallList[i]->type); |
| 202 | printf("test string is %s\n",dataCallList[i]->ifname); |
| 203 | printf("test string is %s\n",dataCallList[i]->addresses); |
| 204 | printf("test string is %s\n",dataCallList[i]->dnses); |
| 205 | printf("test string is %s\n",dataCallList[i]->gateways); |
| 206 | printf("test string is %s\n",dataCallList[i]->pcscf); |
| 207 | } |
| 208 | */ |
| 209 | /* |
| 210 | for(int i=0;i<msg.num;i++) |
| 211 | { |
| 212 | printf("test status is %d\n",dataCallList[i].status); |
| 213 | printf("test suggested is %d\n",dataCallList[i].suggestedRetryTime); |
| 214 | printf("test cid is %d\n",dataCallList[i].cid); |
| 215 | printf("test active is %d\n",dataCallList[i].active); |
| 216 | printf("test mtu is %d\n",dataCallList[i].mtu); |
| 217 | printf("test string is %s\n",dataCallList[i].type); |
| 218 | printf("test string is %s\n",dataCallList[i].ifname); |
| 219 | printf("test string is %s\n",dataCallList[i].addresses); |
| 220 | printf("test string is %s\n",dataCallList[i].dnses); |
| 221 | printf("test string is %s\n",dataCallList[i].gateways); |
| 222 | printf("test string is %s\n",dataCallList[i].pcscf); |
| 223 | } |
| 224 | */ |
| 225 | return token; |
| 226 | |
| 227 | } |
| 228 | void copyDataCallList(LYNQ_Data_Call_Response_v11 *newMsg,const RIL_Data_Call_Response_v11 oldMsg) |
| 229 | { |
| 230 | newMsg->status = oldMsg.status; |
| 231 | LYDBGLOG("test dataCallList status is %d,list status is %d\n",newMsg->status,oldMsg.status); |
| 232 | newMsg->suggestedRetryTime = oldMsg.suggestedRetryTime; |
| 233 | LYDBGLOG("test %d\n",oldMsg.suggestedRetryTime); |
| 234 | newMsg->cid = oldMsg.cid; |
| 235 | LYDBGLOG("test %d\n",oldMsg.cid); |
| 236 | newMsg->active = oldMsg.active; |
| 237 | LYDBGLOG("test %d\n",oldMsg.active); |
| 238 | newMsg->mtu = oldMsg.mtu; |
| 239 | LYDBGLOG("test %d\n",oldMsg.mtu); |
| 240 | memcpy(newMsg->type,oldMsg.type,strlen(oldMsg.type)+1); |
| 241 | LYDBGLOG("test string is %s\n",oldMsg.type); |
| 242 | memcpy(newMsg->ifname,oldMsg.ifname,strlen(oldMsg.ifname)+1); |
| 243 | LYDBGLOG("test string is %s\n",oldMsg.ifname); |
| 244 | memcpy(newMsg->addresses,oldMsg.addresses,strlen(oldMsg.addresses)+1); |
| 245 | LYDBGLOG("test string is %s\n",oldMsg.addresses); |
| 246 | memcpy(newMsg->dnses,oldMsg.dnses,strlen(oldMsg.dnses)+1); |
| 247 | LYDBGLOG("test string is %s\n",oldMsg.dnses); |
| 248 | memcpy(newMsg->gateways,oldMsg.gateways,strlen(oldMsg.gateways)+1); |
| 249 | LYDBGLOG("test string is %s\n",oldMsg.gateways); |
| 250 | memcpy(newMsg->pcscf,oldMsg.pcscf,strlen(oldMsg.pcscf)+1); |
| 251 | LYDBGLOG("test string is %s\n",oldMsg.pcscf); |
| 252 | |
| 253 | } |
| 254 | |