Exemplo n.º 1
0
void KPDP_SetupPdpHandler(void *pdp_cmd, Kpdp_CAPI2Info_t *capi2_rsp)
{
    KPDP_CmdList_t *pdata = (KPDP_CmdList_t *)pdp_cmd;
    static KpdpPdpContext_t gContext;

    if((pdata->handler_state!= BCM_SendCAPI2Cmd)&& (capi2_rsp == NULL))
    {
        KPDP_DEBUG(DBG_ERROR,"capi2_rsp is NULL=%d\n");
        pdata->handler_state = BCM_ErrorCAPI2Cmd;
        return;                            
    }

    switch(pdata->handler_state)
    {
        case BCM_SendCAPI2Cmd:
        {
            UInt8 pindex;
            char chPdpType[PDP_TYPE_LEN_MAX] = "IP";
            pdata->handler_state = BCM_RESPCAPI2Cmd;

            if (NULL == pdata->pdp_cmd->data)
            {
                KPDP_DEBUG(DBG_ERROR, "PDPActivate Fail with NULL data\n");
                pdata->result = RESULT_ERROR;
                pdata->handler_state = BCM_ErrorCAPI2Cmd;
                break;
            }

            memcpy(&gContext, (KpdpPdpContext_t *)(pdata->pdp_cmd->data), sizeof(KpdpPdpContext_t));
            KPDP_DEBUG(DBG_INFO, "KPDP_SetupPdpHandler - Set PDP Context : apn %s\n", gContext.apn);

            if (gContext.cid!=0)
            {
                KPDP_DEBUG(DBG_INFO, "PDPActivate, cid passed in as of %d\n", gContext.cid);
                if (AddDunPdpContext(pdata->pdp_cmd->SimId, gContext.cid) == BCM_NET_MAX_DUN_PDP_CNTXS)
                {
                    KPDP_DEBUG(DBG_ERROR, "PDPActivate Fail with already existing cid %d\n", gContext.cid);
                    pdata->result = RESULT_ERROR;
                    pdata->handler_state = BCM_ErrorCAPI2Cmd;
                    break;
                }

                //Build PCHP
                if (gContext.authtype == AUTH_CHAP)
                {
                    SendCHAPOptions(pdata->pdp_cmd->SimId, &gContext);
                    pdata->handler_state = BCM_PDP_SetPdpOption2;
                }
                else 
                {
                    SendPAPOptions(pdata->pdp_cmd->SimId, &gContext);
                    pdata->handler_state = BCM_PDP_SetPdpOption;
                }
                break;
            }

            if (BCM_NET_MAX_DUN_PDP_CNTXS == (pindex = GetFreeDunPdpContext(pdata->pdp_cmd->SimId)))
            {
                KPDP_DEBUG(DBG_ERROR, "PDPActivate Fail with over max cid[%d]\n", pindex);
                pdata->result = RESULT_ERROR;
                pdata->handler_state = BCM_ErrorCAPI2Cmd;
                break;
            }

            {
                UInt8 numParms = 0;

                if(strlen(gContext.apn) > 0)
                    numParms = 3;
                else
                    numParms = 2;
                gContext.cid = Kpdp_pdp_resp[pdata->pdp_cmd->SimId][pindex].cid;
                FillDataResponseTypeApn(pdata->pdp_cmd->SimId, gContext.cid, chPdpType, gContext.apn);
                KPDP_DEBUG(DBG_INFO,"**Calling CAPI2_PdpApi_SetPDPContext numParms %d type:%s apn:%s pindex %d cid %d\n",numParms, chPdpType, (gContext.apn==NULL)?"NULL":gContext.apn, pindex,Kpdp_pdp_resp[pdata->pdp_cmd->SimId][pindex].cid  );
            
                CAPI2_PdpApi_SetPDPContext( KPDPInitClientInfo(pdata->pdp_cmd->SimId), 
                                            Kpdp_pdp_resp[pdata->pdp_cmd->SimId][pindex].cid, 
                                            numParms, 
                                            chPdpType, 
                                            gContext.apn, 
                                            "", 
                                            0, 
                                            0);
            }
  
            pdata->handler_state = BCM_PDP_SetPdpContext;
        }
        break;

        case BCM_PDP_SetPdpContext:
        {
            if(RESULT_OK != capi2_rsp->result)
            {
                KPDP_DEBUG(DBG_ERROR, "PDPActivate Fail to SetPDPContext[%d]\n", gContext.cid);
                ReleaseDunPdpContext(pdata->pdp_cmd->SimId, gContext.cid);
                pdata->result = RESULT_ERROR;
                pdata->handler_state = BCM_ErrorCAPI2Cmd;
                break;
            }

            if (gContext.authtype == AUTH_CHAP)
            {
                SendCHAPOptions(pdata->pdp_cmd->SimId, &gContext);
                pdata->handler_state = BCM_PDP_SetPdpOption2;
            }
            else 
            {
                SendPAPOptions(pdata->pdp_cmd->SimId, &gContext);
                pdata->handler_state = BCM_PDP_SetPdpOption;
            }
        }
        break;

        case BCM_PDP_SetPdpOption:
        {
            CAPI2_PchExApi_BuildIpConfigOptions_Rsp_t *rsp = (CAPI2_PchExApi_BuildIpConfigOptions_Rsp_t *)capi2_rsp->dataBuf;

            KPDP_DEBUG(DBG_INFO, "KPDP_SetupPdpHandler - Activate PDP context \n");

            if( (RESULT_OK != capi2_rsp->result) || (rsp==NULL))
            {
                KPDP_DEBUG(DBG_ERROR, "CAPI2_PchExApi_BuildIpConfigOptions Fail\n");
                ReleaseDunPdpContext(pdata->pdp_cmd->SimId, gContext.cid);                
                pdata->result = RESULT_ERROR;
                pdata->handler_state = BCM_ErrorCAPI2Cmd;
                break;
            }

            CAPI2_PchExApi_SendPDPActivateReq(KPDPInitClientInfo(pdata->pdp_cmd->SimId), gContext.cid, ACTIVATE_MMI_IP_RELAY, &(rsp->cie));
            pdata->handler_state = BCM_RESPCAPI2Cmd;
        }
        break;

        case BCM_PDP_SetPdpOption2:
        {            
            CAPI2_PchExApi_BuildIpConfigOptions2_Rsp_t *rsp = (CAPI2_PchExApi_BuildIpConfigOptions2_Rsp_t *)capi2_rsp->dataBuf;

            KPDP_DEBUG(DBG_INFO, "KPDP_SetupPdpHandler - Activate PDP context \n");
            if( (RESULT_OK != capi2_rsp->result) || (rsp==NULL))
            {
                KPDP_DEBUG(DBG_ERROR, "CAPI2_PchExApi_BuildIpConfigOptions2 Fail\n");
                ReleaseDunPdpContext(pdata->pdp_cmd->SimId, gContext.cid);
                pdata->result = RESULT_ERROR;
                pdata->handler_state = BCM_ErrorCAPI2Cmd;
                break;
            }	    
            
            CAPI2_PchExApi_SendPDPActivateReq(KPDPInitClientInfo(pdata->pdp_cmd->SimId), gContext.cid, ACTIVATE_MMI_IP_RELAY, &(rsp->ip_cnfg));
            pdata->handler_state = BCM_RESPCAPI2Cmd;
        }
        break;

        case BCM_RESPCAPI2Cmd:
        {
            UInt32 u_pDNS1, u_sDNS1, u_pDNS2, u_sDNS2, u_act_pDNS, u_act_sDNS;
            pdata->bcm_pdp_rsp = kmalloc(sizeof(KpdpPdpData_t), GFP_KERNEL);
            if(!pdata->bcm_pdp_rsp) {
                KPDP_DEBUG(DBG_ERROR, "unable to allocate bcm_pdp_rsp buf\n");
                pdata->handler_state = BCM_ErrorCAPI2Cmd;
                return;
            }
            pdata->rsp_len = sizeof(KpdpPdpData_t);
            memset(pdata->bcm_pdp_rsp, 0, pdata->rsp_len);

            KPDP_DEBUG(DBG_INFO, "result:0x%x\n", capi2_rsp->result);
            if(RESULT_OK != capi2_rsp->result)
            {
                KPDP_DEBUG(DBG_ERROR, "PDPActivate Fail to SendPDPActivateReq[%d] \n", gContext.cid);
                ReleaseDunPdpContext(pdata->pdp_cmd->SimId, gContext.cid);                
                pdata->result = RESULT_ERROR;
                pdata->handler_state = BCM_ErrorCAPI2Cmd;
                break;
            }

            if(NULL != capi2_rsp->dataBuf)
            {
                PDP_SendPDPActivateReq_Rsp_t *rsp = (PDP_SendPDPActivateReq_Rsp_t *)capi2_rsp->dataBuf;
                KpdpPdpData_t *rdata = pdata->bcm_pdp_rsp;

                if((rsp->cause != RESULT_OK) || (rsp->response != PCH_REQ_ACCEPTED))
                {
                    KPDP_DEBUG(DBG_ERROR, "PDPActivate Fail cause %d, resp(1 accept) %d, cid %d\r\n",
                        rsp->cause, rsp->response, rsp->activatedContext.cid);
                    ReleaseDunPdpContext(pdata->pdp_cmd->SimId, gContext.cid);                    
                    rdata->cause = rsp->cause;
                    pdata->result = RESULT_ERROR;
                    pdata->handler_state = BCM_ErrorCAPI2Cmd;
                    break;
                }

                if ((strlen(rsp->activatedContext.pdpAddress)>0) && (strlen(rsp->activatedContext.pdpAddress)<PDP_ADDRESS_LEN_MAX))
                {
                    memcpy(rdata->pdpAddress, rsp->activatedContext.pdpAddress, PDP_ADDRESS_LEN_MAX);
                    KPDP_DEBUG(DBG_INFO, "\nPDP Activate: PDP Address %s \r\n", rdata->pdpAddress);
                }

                u_pDNS1 = u_sDNS1 = u_pDNS2 = u_sDNS2 = u_act_pDNS = u_act_sDNS = 0;
                Capi2ReadDnsSrv(&(rsp->activatedContext.protConfig), &u_pDNS1, &u_sDNS1, &u_pDNS2, &u_sDNS2);

                KPDP_DEBUG(DBG_INFO, "\nPDP Activate: pDns1 0x%x, sDns1 0x%x, pDns2 0x%x, sDns2 0x%x \r\n",
                    (unsigned int)u_pDNS1, (unsigned int)u_sDNS1, (unsigned int)u_pDNS2, (unsigned int)u_sDNS2);

                if((u_act_pDNS = u_pDNS1) == 0)
                {
                    u_act_pDNS = u_pDNS2;
                }
                if((u_act_sDNS = u_sDNS1) == 0)
                {
                    u_act_sDNS = u_sDNS2;
                }
                rdata->priDNS = u_act_pDNS;
                rdata->secDNS = u_act_sDNS;
                rdata->cid = rsp->activatedContext.cid;
                KPDP_DEBUG(DBG_INFO, "PDP Activate Resp - cid %d \n", rsp->activatedContext.cid);
                FillDataResponseAddress(pdata->pdp_cmd->SimId, rdata->cid, rdata->pdpAddress);
                pdata->result = RESULT_OK;
                pdata->handler_state = BCM_FinishCAPI2Cmd;
            }
            else
            {
                pdata->result = RESULT_ERROR;
                pdata->handler_state = BCM_ErrorCAPI2Cmd;
            }
        }
        break;

        default:
        {
            KPDP_DEBUG(DBG_ERROR, "handler_state:%lu error...!\n", pdata->handler_state);
            pdata->handler_state = BCM_ErrorCAPI2Cmd;
            break;
        }
    }
}
Exemplo n.º 2
0
void KRIL_SetupPdpHandler(void *ril_cmd, Kril_CAPI2Info_t *capi2_rsp)
{
    KRIL_CmdList_t *pdata = (KRIL_CmdList_t *)ril_cmd;
    static KrilPdpContext_t gContext;
    UInt8 i;

    if (NULL != capi2_rsp)
        KRIL_DEBUG(DBG_INFO, "BCM_RESPCAPI2Cmd::result:0x%x\n", capi2_rsp->result);

    switch(pdata->handler_state)
    {
        case BCM_SendCAPI2Cmd:
        {
            UInt8 pindex;
            char chPdpType[PDP_TYPE_LEN_MAX] = "IP";

            if (NULL == pdata->ril_cmd->data)
            {
                KRIL_DEBUG(DBG_ERROR, "PDPActivate Fail with NULL data\n");
                pdata->result = BCM_E_GENERIC_FAILURE;
                pdata->handler_state = BCM_ErrorCAPI2Cmd;
                break;
            }

            memcpy(&gContext, (KrilPdpContext_t *)(pdata->ril_cmd->data), sizeof(KrilPdpContext_t));

            if (gContext.apn != NULL)
            {
                for (i=0; i<BCM_NET_MAX_RIL_PDP_CNTXS; i++)
                {
                    if (strcmp(gContext.apn, pdp_resp[i].apn) == 0)
                    {
                        if (pdp_resp[i].active == 2) // connected
                        {
                            KrilPdpData_t *rdata;
                            KRIL_DEBUG(DBG_ERROR, "KRIL_SetupPdpHandler - Data already setup : apn %s \n", gContext.apn);                    
                            pdata->bcm_ril_rsp = kmalloc(sizeof(KrilPdpData_t), GFP_KERNEL);
                            pdata->rsp_len = sizeof(KrilPdpData_t);
                            rdata = pdata->bcm_ril_rsp;

                            memset(pdata->bcm_ril_rsp, 0, pdata->rsp_len);

                            if (pdp_resp[i].address != NULL)
                            {
                                memcpy(rdata->pdpAddress, pdp_resp[i].address, PDP_ADDRESS_LEN_MAX);
                            }

                            if (pdp_resp[i].apn != NULL)
                            {
                                memcpy(rdata->apn, pdp_resp[i].apn, PDP_APN_LEN_MAX);
                            }
                            rdata->cid = pdp_resp[i].cid;
                            
                            pdata->result = BCM_E_SUCCESS;
                            pdata->handler_state = BCM_FinishCAPI2Cmd;
                            return;
                        }
                        else if (pdp_resp[i].active == 3)// connecting
                        {
                            KRIL_DEBUG(DBG_ERROR, "KRIL_SetupPdpHandler - Ignore due to state(Connecting) : apn %s \n", gContext.apn);                    
                            pdata->result = BCM_E_GENERIC_FAILURE;
                            pdata->handler_state = BCM_ErrorCAPI2Cmd;
                            return;
                        }
                    }
                }
            }

            if (BCM_NET_MAX_RIL_PDP_CNTXS == (pindex = GetFreePdpContext()))
            {
                KRIL_DEBUG(DBG_ERROR, "PDPActivate Fail with over max cid[%d]\n", pindex);
                pdata->result = BCM_E_GENERIC_FAILURE;
                pdata->handler_state = BCM_ErrorCAPI2Cmd;
                break;
            }

            KRIL_DEBUG(DBG_INFO, "KRIL_SetupPdpHandler - Set PDP Context : apn %s \n", gContext.apn);

            {
                ClientInfo_t clientInfo;
                UInt8 numParms = (gContext.apn == NULL)?2:3;
                CAPI2_InitClientInfo(&clientInfo, GetNewTID(), GetClientID());
                gContext.cid = pdp_resp[pindex].cid;
                FillDataResponseTypeApn(gContext.cid, chPdpType, gContext.apn);
                KRIL_DEBUG(DBG_INFO,"**Calling CAPI2_PdpApi_SetPDPContext numParms %d type:%s apn:%s pindex %d cid %d\n",numParms, chPdpType, (gContext.apn==NULL)?"NULL":gContext.apn, pindex,pdp_resp[pindex].cid  );
            
				KRIL_SetInSetupPDPHandler(TRUE);
				
                CAPI2_PdpApi_SetPDPContext( &clientInfo, 
                                            pdp_resp[pindex].cid, 
                                            numParms, 
                                            chPdpType, 
                                            gContext.apn, 
                                            "", 
                                            0, 
                                            0);
            }
  
            pdp_resp[pindex].active = 3; //connecting

            pdata->handler_state = BCM_PDP_SetPdpContext;
        }
        break;

        case BCM_PDP_SetPdpContext:
        {
            PCHProtConfig_t t_PCHP;
            char *username = gContext.username;
            char *password = gContext.password;
            IPConfigAuthType_t t_Authtype = REQUIRE_PAP;/*default setting*/
            //UInt8 ContextID = 1;
            KRIL_DEBUG(DBG_INFO, "KRIL_SetupPdpHandler - Activate PDP context \n");

            if(RESULT_OK != capi2_rsp->result)
            {
                KRIL_DEBUG(DBG_ERROR, "PDPActivate Fail to SetPDPContext[%d]\n", gContext.cid);
                ReleasePdpContext(gContext.cid);
                pdata->result = BCM_E_GENERIC_FAILURE;
                pdata->handler_state = BCM_ErrorCAPI2Cmd;
				
				KRIL_SetInSetupPDPHandler(FALSE);
                break;
            }

            if (AUTH_PAP == gContext.authtype)
                t_Authtype = REQUIRE_PAP;
            else if (AUTH_CHAP == gContext.authtype)
                t_Authtype = REQUIRE_CHAP;

            memset(&t_PCHP, 0, sizeof(PCHProtConfig_t));
            // **FIXME** MAG - update this to use CAPI2_PCHEx_BuildIpConfigOptions() when api
            // is fixed in CIB CP (likely .30 release or so)
            Capi2BuildIpConfigOptions(&t_PCHP, username, password, t_Authtype);
            {
                ClientInfo_t clientInfo;
                CAPI2_InitClientInfo( &clientInfo, GetNewTID(), GetClientID());
                CAPI2_PchExApi_SendPDPActivateReq( &clientInfo, gContext.cid, ACTIVATE_MMI_IP_RELAY, &t_PCHP );
            }
            pdata->handler_state = BCM_RESPCAPI2Cmd;
        }
        break;

        case BCM_RESPCAPI2Cmd:
        {
            UInt32 u_pDNS1, u_sDNS1, u_pDNS2, u_sDNS2, u_act_pDNS, u_act_sDNS;
            pdata->bcm_ril_rsp = kmalloc(sizeof(KrilPdpData_t), GFP_KERNEL);
            pdata->rsp_len = sizeof(KrilPdpData_t);
            memset(pdata->bcm_ril_rsp, 0, pdata->rsp_len);

            KRIL_DEBUG(DBG_INFO, "result:0x%x\n", capi2_rsp->result);
            if(RESULT_OK != capi2_rsp->result)
            {
                KRIL_DEBUG(DBG_ERROR, "PDPActivate Fail to SendPDPActivateReq[%d] \n", gContext.cid);
                ReleasePdpContext(gContext.cid);
                pdata->result = BCM_E_GENERIC_FAILURE;
                pdata->handler_state = BCM_ErrorCAPI2Cmd;
				KRIL_SetInSetupPDPHandler(FALSE);
                break;
            }

            if(NULL != capi2_rsp->dataBuf)
            {
                PDP_SendPDPActivateReq_Rsp_t *rsp = (PDP_SendPDPActivateReq_Rsp_t *)capi2_rsp->dataBuf;
                KrilPdpData_t *rdata = pdata->bcm_ril_rsp;

                if((rsp->cause != RESULT_OK) || (rsp->response != PCH_REQ_ACCEPTED))
                {
                    KRIL_DEBUG(DBG_ERROR, "PDPActivate Fail cause %d, resp(1 accept) %d, cid %d\r\n",
                        rsp->cause, rsp->response, rsp->activatedContext.cid);
                    ReleasePdpContext(gContext.cid);
                    rdata->cause = ParsePdpFailCause(rsp->cause);
                    pdata->result = BCM_E_RADIO_NOT_AVAILABLE;
                    pdata->handler_state = BCM_ErrorCAPI2Cmd;
					
					KRIL_SetInSetupPDPHandler(FALSE);
                    break;
                }

                if (NULL != rsp->activatedContext.pdpAddress)
                {
                    memcpy(rdata->pdpAddress, rsp->activatedContext.pdpAddress, PDP_ADDRESS_LEN_MAX);
                    KRIL_DEBUG(DBG_INFO, "PDP Activate: PDP Address %s \r\n", rdata->pdpAddress);
                }

                u_pDNS1 = u_sDNS1 = u_pDNS2 = u_sDNS2 = u_act_pDNS = u_act_sDNS = 0;
                Capi2ReadDnsSrv(&(rsp->activatedContext.protConfig), &u_pDNS1, &u_sDNS1, &u_pDNS2, &u_sDNS2);

                KRIL_DEBUG(DBG_INFO, "PDP Activate: pDns1 0x%x, sDns1 0x%x, pDns2 0x%x, sDns2 0x%x \r\n",
                    (unsigned int)u_pDNS1, (unsigned int)u_sDNS1, (unsigned int)u_pDNS2, (unsigned int)u_sDNS2);

                if((u_act_pDNS = u_pDNS1) == 0)
                {
                    u_act_pDNS = u_pDNS2;
                }
                if((u_act_sDNS = u_sDNS1) == 0)
                {
                    u_act_sDNS = u_sDNS2;
                }
                rdata->priDNS = u_act_pDNS;
                rdata->secDNS = u_act_sDNS;
                rdata->cid = rsp->activatedContext.cid;
                KRIL_DEBUG(DBG_INFO, "PDP Activate Resp - cid %d \n", rsp->activatedContext.cid);
                FillDataResponseAddress(rdata->cid, rdata->pdpAddress);

                for (i=0; i<BCM_NET_MAX_RIL_PDP_CNTXS; i++)
                {
                    if (rdata->cid == pdp_resp[i].cid)
                    {
                        if (pdp_resp[i].apn != NULL)
                        {
                            memcpy(rdata->apn, pdp_resp[i].apn, PDP_APN_LEN_MAX);
                        }
                        break;
                    }
                }

                pdata->result = BCM_E_SUCCESS;
                pdata->handler_state = BCM_FinishCAPI2Cmd;
            }
            else
            {
                pdata->result = BCM_E_GENERIC_FAILURE;
                pdata->handler_state = BCM_ErrorCAPI2Cmd;
            }
			
			KRIL_SetInSetupPDPHandler(FALSE);
        }
        break;

        default:
        {
			KRIL_SetInSetupPDPHandler(FALSE);
            KRIL_DEBUG(DBG_ERROR, "handler_state:%lu error...!\n", pdata->handler_state);
            pdata->handler_state = BCM_ErrorCAPI2Cmd;
            break;
        }
    }
}