int main(int argc, char * arg[]) { EIP_UINT8 acMyMACAddress[6]; EIP_UINT16 nUniqueConnectionID; if(argc != 12) { printf("Wrong number of command line parameters!\n"); printf("The correct command line parameters are:\n"); printf( "./opener ipaddress subnetmask gateway domainname hostaddress macaddress\n"); printf( " e.g. ./opener 192.168.0.2 255.255.255.0 192.168.0.1 test.com testdevice 00 15 C5 BF D0 87\n"); exit(0); } else { /* fetch Internet address info from the platform */ configureNetworkInterface(arg[1], arg[2], arg[3]); configureDomainName(arg[4]); configureHostName(arg[5]); acMyMACAddress[0] = (EIP_UINT8) strtoul(arg[6], NULL, 16); acMyMACAddress[1] = (EIP_UINT8) strtoul(arg[7], NULL, 16); acMyMACAddress[2] = (EIP_UINT8) strtoul(arg[8], NULL, 16); acMyMACAddress[3] = (EIP_UINT8) strtoul(arg[9], NULL, 16); acMyMACAddress[4] = (EIP_UINT8) strtoul(arg[10], NULL, 16); acMyMACAddress[5] = (EIP_UINT8) strtoul(arg[11], NULL, 16); configureMACAddress(acMyMACAddress); } /*for a real device the serial number should be unique per device */ setDeviceSerialNumber(123456789); /* nUniqueConnectionID should be sufficiently random or incremented and stored * in non-volatile memory each time the device boots. */ nUniqueConnectionID = rand(); /* Setup the CIP Layer */ CIP_Init(nUniqueConnectionID); /* Setup Network Handles */ if(EIP_OK == NetworkHandler_Init()) { g_nEndStack = 0; #ifndef WIN32 /* register for closing signals so that we can trigger the stack to end */ signal(SIGHUP, leaveStack); #endif /* The event loop. Put other processing you need done continually in here */ while(1 != g_nEndStack) { if(EIP_OK != NetworkHandler_ProcessOnce()) { break; } } /* clean up network state */ NetworkHandler_Finish(); } /* close remaining sessions and connections, cleanup used data */ shutdownCIP(); return -1; }
/* Change name from requestDeactiveDefaultPdp to requestDeactiveDataCall */ void requestDeactiveDataCall(void * data, size_t datalen, RIL_Token t) { const char *cid; char *cmd; int err; ATResponse *p_response = NULL; int i = 0, lastPdnCid; int interfaceId = atoi(((const char **)data)[0]); LOGD("requestDeactiveDataCall interfaceId=%d", interfaceId); int needHandleLastPdn = 0; // AT+CGACT=<state>,<cid>; <state>:0-deactivate;1-activate for(i = 0; i < max_pdn_support; i++) { if (pdn_info[i].interfaceId == interfaceId) { asprintf(&cmd, "AT+CGACT=0,%d", i); err = at_send_command(cmd, &p_response, DATA_CHANNEL_CTX); free(cmd); if (isATCmdRspErr(err, p_response)) { if (p_response->success == 0) { int error = at_get_cme_error(p_response); if (error == CME_L4C_CONTEXT_CONFLICT_DEACT_ALREADY_DEACTIVATED) { //L4C error: L4C_CONTEXT_CONFLICT_DEACT_ALREADY_DEACTIVATED(0x1009) LOGD("requestDeactiveDataCall cid%d already deactivated", i); } else if (error == CME_LAST_PDN_NOT_ALLOW) { if (needHandleLastPdn == 0) { LOGD("requestDeactiveDataCall cid%d is the last PDN", i); needHandleLastPdn = 1; lastPdnCid = i; } } } else { LOGD("requestDeactiveDataCall cid%d AT+CGACT response fail", i); goto error; } } AT_RSP_FREE(p_response); } } configureNetworkInterface(interfaceId, 0); setDataSystemProperties(interfaceId); for(i = 0; i < max_pdn_support; i++) { //fixed network interface not disable issue while deactivating) if (pdn_info[i].interfaceId == interfaceId) clearPdnInfo(&pdn_info[i]); } if (needHandleLastPdn) { // Always link down the last PDN. asprintf(&cmd, "AT+EGLD=%d", lastPdnCid); err = at_send_command(cmd, &p_response, DATA_CHANNEL_CTX); free(cmd); if (isATCmdRspErr(err, p_response)) { LOGE("requestDeactiveDataCall handleLastPdn link down ERROR"); goto error; } pdn_info[lastPdnCid].active = DATA_STATE_LINKDOWN; AT_RSP_FREE(p_response); } #if defined(PURE_AP_USE_EXTERNAL_MODEM) updateAvailablePdpNum(); #endif //response deactivation result first then do re-attach RIL_onRequestComplete(t, RIL_E_SUCCESS, NULL, 0); AT_RSP_FREE(p_response); return; error: RIL_onRequestComplete(t, RIL_E_GENERIC_FAILURE, NULL, 0); AT_RSP_FREE(p_response); }