/************* * Crashing program for SDK it is modified example start_sdk.c * * Purpose: start sdk with readyagent enable * * Copyright: © 2013 Sierra Wireless Inc., all rights reserved * **************/ #define _GNU_SOURCE #include "SWIWWANCMAPI.h" #include "qmerrno.h" #include #include #include #include #include #include #include #include #include #include #include #include /**************************************************************** * DEFINES ****************************************************************/ #define SUCCESS 0 #define DEV_NODE_SZ 256 #define DEV_KEY_SZ 16 #define FALSE 0 #define TRUE 1 /**************************************************************** * DATA STRUCTURE ****************************************************************/ /* Device information structure */ typedef struct device_info_param{ CHAR deviceNode[DEV_NODE_SZ]; CHAR deviceKey[DEV_KEY_SZ]; }device_info_t; /* path to sdk binary */ static char *sdkbinpath = NULL; /* device connectivity */ static device_info_t devices[1] = { { {'\0'}, {'\0'} } }; static device_info_t *pdev = &devices[0]; static BYTE devicemode = DCS_DEVICE_MODE_DISCONNECTED; /************************************************************************* Signal handler: To take care of process *************************************************************************/ /* * Name: appSignalInstall * * Purpose: install signal handler * * Params: None * * Return: None * * Notes: None */ void appSignalInstall( unsigned int signo, void (*functionp)(int, siginfo_t *, void *) ) { struct sigaction sa; if (functionp == NULL) return; sa.sa_sigaction = functionp; sigemptyset(&sa.sa_mask); sa.sa_flags = SA_NODEFER | SA_SIGINFO; if (sigaction(signo, &sa, NULL) < 0) { fprintf(stderr,"Signal handling falied"); } } /* * Name: appSIGCHLDhandler * * Purpose: appSIGCHLDhandler * * Params: None * * Return: None * * Notes: None */ void appSIGCHLDhandler (int signo, siginfo_t *siginfop, void *contextp) { int status; UNUSEDPARAM ( signo ); UNUSEDPARAM ( siginfop ); UNUSEDPARAM ( contextp ); /* Allow the SDK process to terminate */ wait(&status); } /* * Name: SignalInit * * Purpose: initialize signal handler * * Params: None * * Return: None * * Notes: None */ void SignalInit() { appSignalInstall (SIGCHLD, appSIGCHLDhandler); } /* * Name: StartSDK * * Purpose: It starts the SDK by setting the SDK path, enumerates the device * and connects to the SDK. * * Return: SUCCESS on successfully starting SDK, else error code * * Notes: none */ ULONG StartSDK(BYTE modem_index) { ULONG rc = 0; BYTE devicesSize = 1; /* Set SDK image path */ if( eQCWWAN_ERR_NONE != (rc = SetSDKImagePath(sdkbinpath)) ) { fprintf(stderr, "Failed to set the SDK Image path (%lx)\n", rc); return rc; } /* Establish APP<->SDK IPC */ if( eQCWWAN_ERR_SWICM_SOCKET_IN_USE == (rc = SLQSStart(modem_index)) ) { fprintf(stderr, "Another APP is currently using the SDK (%lx)\n", rc); return rc; } else if( eQCWWAN_ERR_NONE != rc ) { return rc; } rc = SLQSGetDeviceMode ((BYTE *)&devicemode); /* Can enumerate and connect only if device is in Application mode */ if ( devicemode == DCS_DEVICE_MODE_READY ) { /* Enumerate the device */ while( QCWWAN2kEnumerateDevices( &devicesSize, (BYTE *)(pdev) ) != 0 ) { printf ("\nUnable to find device..\n"); sleep(1); } fprintf( stderr, "#devices: %d\ndeviceNode: %s\ndeviceKey: %s\n", devicesSize, pdev->deviceNode, pdev->deviceKey ); /* Connect to the SDK */ rc = QCWWANConnect( pdev->deviceNode, pdev->deviceKey ); } return rc; } /* * Name: DisplayRSSInfo * * Purpose: Display receive Signal strength information * * Params: None * * Return: None * * Notes: None */ void DisplayRSSInfo() { struct slqsSignalStrengthInfo rssInfo; ULONG resultCode = 0; /* Mask all bits to receive complete information */ rssInfo.signalStrengthReqMask = 0x1F; /* Get the information about the received Signal Strength */ resultCode = SLQSGetSignalStrength( &rssInfo ); if( SUCCESS != resultCode ) { fprintf( stderr, "Failed to get RSS Information\n" ); fprintf( stderr, "Failure Code : %lu\n", resultCode ); return; } } int main( int argc, const char *argv[]) { ULONG resultCode = 0; if( argc < 1 ) { fprintf( stderr, "usage: %s \n", argv[0] ); exit( EXIT_SUCCESS ); } if( NULL == (sdkbinpath = malloc(strlen(argv[1]) + 1)) ) { perror(__func__); exit( EXIT_FAILURE ); } strncpy( sdkbinpath, argv[1], strlen(argv[1]) + 1); /* Initialize signal handler */ SignalInit(); /* Start the SDk */ resultCode = StartSDK(0); if( eQCWWAN_ERR_NONE != resultCode ) { free(sdkbinpath); /* Display the failure reason */ fprintf( stderr, "Failed to start SDK: Exiting App\n"\ "Failure Code: %lu\n", resultCode ); /* Failed to start SDK, exit the application */ exit( EXIT_FAILURE ); } DisplayRSSInfo(); /*Killing SDK process is important for crashing SDK*/ SLQSKillSDKProcess(); return 1; }