static UInt8 AddDunPdpContext(SimNumber_t SimId, UInt8 cid)
{
    UInt8 i;
   
    //index to be added to
    i = DUN_PDP_INDEX(cid);

    if (i >= BCM_NET_MAX_DUN_PDP_CNTXS)
    {
	KPDP_DEBUG(DBG_ERROR, "AddDunPdpContext cid=%d exceeds the range \n", cid);
        return BCM_NET_MAX_DUN_PDP_CNTXS;
    }
 
    if (cid == Kpdp_pdp_resp[SimId][i].cid)
    {
        //make this warning only, 'cause there are cases pdp context gets reused.
        KPDP_DEBUG(DBG_INFO, "AddDunPdpContext SimId:%d cid=%d already exists at [%d], error \n", SimId, cid, i);
    }
    else
    {
        Kpdp_pdp_resp[SimId][i].cid = cid;
        KPDP_DEBUG(DBG_INFO, "AddDunPdpContext SimId:%d cid=%d already exists at [%d]\n", SimId, cid, i);
    }

    return i;
}
Exemple #2
0
static int KPDP_Open(struct inode *inode, struct file *filp)
{
    KPDP_Param_t *priv;

    priv = kmalloc(sizeof(*priv), GFP_KERNEL);
    if (!priv)
        return -ENOMEM;

    KPDP_DEBUG(DBG_INFO, "KPDP_Open %s: major %d minor %d (pid %d)\n", __func__, imajor(inode), iminor(inode), current->pid);

    priv->file = filp;
    filp->private_data = priv;

    /*init response*/
    spin_lock_init(&(priv->recv_lock));
    INIT_LIST_HEAD(&(gKpdpResultQueue.list));

    init_waitqueue_head(&gKpdpParam.read_wait);
    mutex_init(&priv->recv_mutex);

    KPDP_DEBUG(DBG_INFO, "i_private=%p private_data=%p, wait=%p\n", inode->i_private, filp->private_data, &priv->recv_wait);

    gKpdpParam.recv_lock = priv->recv_lock;
    return 0;
}
UInt8 FindDunPdpCid(SimNumber_t SimId)
{
    UInt8 i;
    for (i=0; i<BCM_NET_MAX_DUN_PDP_CNTXS; i++)
    {        
        KPDP_DEBUG(DBG_ERROR, "Kpdp_pdp_resp[%d][%d]=%d \n", SimId, i, Kpdp_pdp_resp[SimId][i].cid);
        if (Kpdp_pdp_resp[SimId][i].cid != 0)
        {
            KPDP_DEBUG(DBG_ERROR, "Kpdp_pdp_resp[%d][%d]=%d \n", SimId, i, Kpdp_pdp_resp[SimId][i].cid);
            return Kpdp_pdp_resp[SimId][i].cid;
        }
    }
    return BCM_NET_MAX_DUN_PDP_CNTXS+1;
}
Exemple #4
0
/****************************************************************************
*
*  bcm_fuse_kpdp_init_module(void);
*
*  Init module.
*
***************************************************************************/
static int __init bcm_fuse_kpdp_init_module(void)
{
    int ret = 0;

    KPDP_DEBUG(DBG_INFO, "bcm_fuse_kpdp_init_module()");
    pr_info("KPDP Support 1.00 (BUILD TIME "__DATE__" "__TIME__")\n" );

    if ( AP_ONLY_BOOT == get_ap_boot_mode() )
    {
        KPDP_DEBUG(DBG_INFO, "bcm_fuse_kpdp_init_module: AP only; don't register driver\n");
        return ret;
    }

    if (( ret = register_chrdev( BCM_KPDP_MAJOR, "bcm_kpdp", &kpdp_ops )) < 0 )
    {
        KPDP_DEBUG(DBG_ERROR, "kpdp: register_chrdev failed for major %d\n", BCM_KPDP_MAJOR );
        goto out;
    }

    kpdp_class = class_create(THIS_MODULE, "bcm_kpdp");
    if (IS_ERR(kpdp_class)) {
        return PTR_ERR(kpdp_class);
    }

    device_create(kpdp_class, NULL, MKDEV(BCM_KPDP_MAJOR, 0),NULL, "bcm_kpdp");

    KPDP_DEBUG(DBG_INFO, "%s driver(major %d) installed.\n", "bcm_kpdp", BCM_KPDP_MAJOR);
    /**
       Register callbacks with the IPC module
       Note: does not depend on the channel
    */
    ret = KPDPCAPI2_ClientInit();

    /** Init KPDP Driver */
    ret = KPDP_Init();

    if (ret) 
    {
        ret = -1;
        KPDP_DEBUG(DBG_ERROR, "KPDP_Init fail...!\n");
        goto out_unregister;
    }

    return ret;
out_unregister:
    unregister_chrdev( BCM_KPDP_MAJOR, "bcm_kpdp");
out:
   return(ret);
}
static UInt8 GetFreeDunPdpContext(SimNumber_t SimId)
{
    UInt8 i;
    KPDP_DEBUG(DBG_ERROR, "SimID:%d GetFreeDunPdpContext\n", SimId);
    for (i=0; i<BCM_NET_MAX_DUN_PDP_CNTXS; i++)
    {
        if (0 == Kpdp_pdp_resp[SimId][i].cid)
        {
            Kpdp_pdp_resp[SimId][i].cid = DUN_PDP_CID(i);
            KPDP_DEBUG(DBG_INFO, "SimID:%d GetFreeDunPdpContext[%d]=%d \n", SimId, i, Kpdp_pdp_resp[SimId][i].cid);
            return i;
        }
    }
    return BCM_NET_MAX_DUN_PDP_CNTXS;
}
Exemple #6
0
int KPDP_Read(struct file *filp, char __user *buf, size_t size, loff_t *offset)
{
    /*buffer copy to user*/
    int rc = 0;
    KPDP_DEBUG(DBG_INFO, "KPDP_Read Enter %s\n", __func__);

    return rc;
}
Exemple #7
0
int KPDP_Write(struct file *filp, const char __user *buf, size_t size, loff_t *offset)
{
    /*buffer copy from user*/
    int rc = 0;
    KPDP_DEBUG(DBG_INFO, "KPDP_Write %s: count %d pos %lld\n", __func__, size, *offset);

    return rc;
}
/* Ack call back */
void KPDP_Capi2HandleAckCbk(UInt32 tid, UInt8 clientid, RPC_ACK_Result_t ackResult, UInt32 ackUsrData)
{
    switch(ackResult)
    {
        case ACK_SUCCESS:
        {
            //capi2 request ack succeed
	        //KPDP_DEBUG(DBG_INFO, "KPDP_HandleCapi2AckCbk::AckCbk ACK_SUCCESS tid=%lu\n", tid);
        }
        break;

        case ACK_FAILED:
        {
	        KPDP_DEBUG(DBG_ERROR, "KPDP_HandleCapi2AckCbk::AckCbk ACK_FAILED\n");
            //capi2 ack fail for unknown reasons
        }
        break;

        case ACK_TRANSMIT_FAIL:
        {
	        KPDP_DEBUG(DBG_ERROR, "KPDP_HandleCapi2AckCbk::AckCbk ACK_TRANSMIT_FAIL\n");
            //capi2 ack fail due to fifo full, fifo mem full etc.
        }
        break;

        case ACK_CRITICAL_ERROR:
        {
            KPDP_DEBUG(DBG_ERROR, "KPDP_HandleCapi2AckCbk::AckCbk ACK_CRITICAL_ERROR\n");
            //capi2 ack fail due to comms processor reset ( The use case for this error is TBD )  
        }
        break;

        default:
        {
            KPDP_DEBUG(DBG_ERROR, "KPDP_HandleCapi2AckCbk::AckCbk ackResult error!\n");
        }
        break;
    }
}
//******************************************************************************
//
// Function Name: ProcessNotification
//
// Description:  Process the notify message from CP side.
//
// Notes:
//
//******************************************************************************
void KPDP_ProcessNotification(Kpdp_CAPI2Info_t *notify)
{
    //KPDP_DEBUG(DBG_TRACE, "msgType:0x%lX!\n", (UInt32)notify->msgType);

    switch((UInt32)notify->msgType)
        {
        case MSG_PDP_DEACTIVATION_IND:
        {
            PDP_PDPDeactivate_Ind_t *pind = (PDP_PDPDeactivate_Ind_t *) notify->dataBuf;
            UInt8 i,Sim_Id;
            
            KPDP_DEBUG(DBG_INFO, "MSG_PDP_DEACTIVATION_IND::cid %d,type[%s],add[%s]\n", pind->cid, pind->pdpType, pind->pdpAddress);
            for(Sim_Id = 0;Sim_Id<DUAL_SIM_SIZE;Sim_Id++) {
                for (i=0; i<BCM_NET_MAX_DUN_PDP_CNTXS; i++)
                {
                    if (pind->cid == Kpdp_pdp_resp[Sim_Id][i].cid)
                    {
                        Kpdp_pdp_resp[Sim_Id][i].active = 0;
                        memset(&Kpdp_pdp_resp[Sim_Id][i], 0, sizeof(KpdpDataCallResponse_t));
                        Kpdp_pdp_resp[Sim_Id][i].cid = pind->cid;
                        KPDP_DEBUG(DBG_INFO, "SimID:%d MSG_PDP_DEACTIVATION_IND[%d]=%d \n", Sim_Id, i, Kpdp_pdp_resp[Sim_Id][i].cid);
                        KPDP_SendNotify(Sim_Id, PDP_UNSOL_DATA_CALL_LIST_CHANGED, &Kpdp_pdp_resp[Sim_Id][i], sizeof(KpdpDataCallResponse_t));
                        Kpdp_pdp_resp[Sim_Id][i].cid = 0; //KPDP_SendNotify has backup Kpdp_Kpdp_pdp_resp by memcpy, so we can modify here
                        //notify user space
                        Kpdp_pdp_deactivate_ind(pind->cid);
                        break;
                    }
                }
            }
            break;
        }
        default:
        {
            //KPDP_DEBUG(DBG_INFO, "The msgType:0x%lX is not process yet...!\n", (UInt32)notify->msgType);
            break;
        }
    }
}
//remember to change to static
void Kpdp_pdp_deactivate_ind(int cid)
{
    //invoke "pdputil Event 1002 (MSG_PDP_DEACTIVATION_IND)" 

    char event_id[10];
    char cid_str[10];
    sprintf(event_id,"%d", PDP_DEACTIVATION_IND);
    sprintf(cid_str,"%d", cid);

    KPDP_DEBUG(DBG_INFO, "invoke \"pdputil Event %s %s\" \n", event_id, cid_str);
    {
        char *event_args[] = {PDPUTIL,"Event", event_id, cid_str, NULL};
        call_usermodehelper(PDPUTIL, event_args, NULL,0);
    }
}
static void FillDataResponseTypeApn(SimNumber_t SimId, UInt8 cid, char* type, char* apn)
{
    UInt8 i;
    for (i=0; i<BCM_NET_MAX_DUN_PDP_CNTXS; i++)
    {
        if (cid == Kpdp_pdp_resp[SimId][i].cid)
        {
            if ((NULL != type) && (strlen(type) < PDP_TYPE_LEN_MAX))
                strcpy(Kpdp_pdp_resp[SimId][i].type, type);
            if ((NULL != apn) && (strlen(apn) < PDP_APN_LEN_MAX))
                strcpy(Kpdp_pdp_resp[SimId][i].apn, apn);
            KPDP_DEBUG(DBG_INFO, "SimId:%d FillDataResponseTypeApn[%d]=[%s][%s] \n", SimId, i, Kpdp_pdp_resp[SimId][i].type, Kpdp_pdp_resp[SimId][i].apn);
            return;
        }
    }
}
static void FillDataResponseAddress(SimNumber_t SimId, UInt8 cid, char* address)
{
    UInt8 i;
    for (i=0; i<BCM_NET_MAX_DUN_PDP_CNTXS; i++)
    {
        if (cid == Kpdp_pdp_resp[SimId][i].cid)
        {
            Kpdp_pdp_resp[SimId][i].active = 2; // 0=inactive, 1=active/physical link down, 2=active/physical link up
            if ((address!=NULL ) && (strlen(address) < PDP_ADDRESS_LEN_MAX))
            {
                strcpy(Kpdp_pdp_resp[SimId][i].address, address);
            }
            KPDP_DEBUG(DBG_INFO, "SimId:%d FillDataResponseAddress[%d]=[%s] \n", SimId, i, Kpdp_pdp_resp[SimId][i].address);
            return;
        }
    }
}
UInt8 ReleaseDunPdpContext(SimNumber_t SimId, UInt8 cid)
{
    UInt8 i;
    for (i=0; i<BCM_NET_MAX_DUN_PDP_CNTXS; i++)
    {
        if (cid == Kpdp_pdp_resp[SimId][i].cid)
        {
            Kpdp_pdp_resp[SimId][i].active = 0;
            //KRIL_SendNotify(SimId, PDP_UNSOL_DATA_CALL_LIST_CHANGED, &pdp_resp[SimId][i], sizeof(KrilDataCallResponse_t));
            //memset(&Kpdp_pdp_resp[SimId][i], 0, sizeof(KpdpDataCallResponse_t));
            Kpdp_pdp_resp[SimId][i].cid = 0;            
            KPDP_DEBUG(DBG_INFO, "SimId:%d ReleaseDunPdpContext[%d]=%d \n", SimId, i, Kpdp_pdp_resp[SimId][i].cid);
            return i;
        }
    }
    return BCM_NET_MAX_DUN_PDP_CNTXS;
}
static void SendCHAPOptions(SimNumber_t SimId, KpdpPdpContext_t* context)
{    
    CHAP_ChallengeOptions_t challOptions;
    CHAP_ResponseOptions_t respOptions;

    KPDP_DEBUG(DBG_INFO, "SendCHAPOptions chall_len=%d, resp_len=%d\r\n", context->chall_len, context->resp_len);

    challOptions.flag=1;
    challOptions.len =context->chall_len;
    memcpy(challOptions.content, context->challenge, PDP_CHALLENGE_LEN_MAX); 
	
    respOptions.flag=1;
    respOptions.len =context->resp_len;
    memcpy(respOptions.content, context->response, PDP_RESPONSE_LEN_MAX); 

    CAPI2_PchExApi_BuildIpConfigOptions2(KPDPInitClientInfo(SimId), REQUIRE_CHAP, &challOptions, &respOptions, NULL);
}
void KPDP_Capi2HandleRespCbk(UInt32 tid, UInt8 clientID, MsgType_t msgType, Result_t result, void *dataBuf, UInt32 dataLength, ResultDataBufHandle_t dataBufHandle)
{
    Kpdp_CAPI2Info_t *capi2_rsp = NULL;

    //KPDP_DEBUG(DBG_INFO, "tid:%lu msgtype:0x%x result:%d\n", tid, msgType, result);
    capi2_rsp = kmalloc(sizeof(Kpdp_CAPI2Info_t), GFP_KERNEL);
    if(!capi2_rsp)
    {
        KPDP_DEBUG(DBG_ERROR, "Unable to allocate CAPI2 Response memory\n");
        RPC_SYSFreeResultDataBuffer(dataBufHandle);
        return;
    }

    capi2_rsp->tid = tid;
    capi2_rsp->clientID = clientID;    
    capi2_rsp->msgType = msgType;
    capi2_rsp->result = result;
    capi2_rsp->dataBuf = dataBuf;
    capi2_rsp->dataLength = dataLength;
    capi2_rsp->dataBufHandle = dataBufHandle;

    if(capi2_rsp->tid == 0) //notify
    {
        unsigned long irql;
#ifdef CONFIG_HAS_WAKELOCK
        wake_lock(&kpdp_notify_wake_lock);
#endif
        spin_lock_irqsave(&gKpdpNotifyWq.lock, irql);
        list_add_tail(&capi2_rsp->list, &gKpdpNotifyWq.capi2_head.list); 
        spin_unlock_irqrestore(&gKpdpNotifyWq.lock, irql);
        queue_work(gKpdpNotifyWq.notify_wq, &gKpdpNotifyWq.notifyq);
    }
    else //response
    {
        unsigned long irql;
#ifdef CONFIG_HAS_WAKELOCK
        wake_lock(&kpdp_rsp_wake_lock);
#endif
        spin_lock_irqsave(&gKpdpRespWq.lock, irql);
        list_add_tail(&capi2_rsp->list, &gKpdpRespWq.capi2_head.list); 
        spin_unlock_irqrestore(&gKpdpRespWq.lock, irql);
        queue_work(gKpdpRespWq.rsp_wq, &gKpdpRespWq.responseq);
    }
}
Exemple #16
0
static unsigned int KPDP_Poll(struct file *filp, poll_table *wait)
{
    KPDP_Param_t *priv = filp->private_data;
    UInt32 mask = 0;
    UInt32 flags;

    poll_wait(filp, &gKpdpParam.read_wait, wait);

    spin_lock_irqsave(&priv->recv_lock, flags);

    if (!list_empty(&(gKpdpResultQueue.list)))
     {
         KPDP_DEBUG(DBG_INFO, "KPDP_Poll() mask \n");
        mask |= (POLLIN | POLLRDNORM);
     }

    spin_unlock_irqrestore(&priv->recv_lock, flags);

   return mask;
}
Exemple #17
0
static long KPDP_Ioctl(struct file *filp, unsigned int cmd, UInt32 arg)
{
    int rc = -1;

    switch(cmd)
    {
        case BCM_KPDPIO_SET_COMMAND:
            rc = KPDP_SendCmd(cmd, arg);
            break;

        case BCM_KPDPIO_GET_RESPONSE:
            rc = KPDP_GetRsp(filp, cmd, arg);
            break;

        default:
            KPDP_DEBUG(DBG_ERROR, "we don't process the kpdp_ioctl cmd:0x%x!\n", cmd);
            break;
    }

    return(rc);
}
Exemple #18
0
Int32 KPDP_SendCmd(UInt32 cmd, UInt32 arg)
{
    KPDP_CmdQueue_t *kpdp_cmd = NULL;
    void *tdata = NULL;


    kpdp_cmd = kmalloc(sizeof(KPDP_CmdQueue_t), GFP_KERNEL);

    if(!kpdp_cmd)
    {
        KPDP_DEBUG(DBG_ERROR, "Unable to allocate kpdp_cmd memory\n");
    }
    else
    {
        kpdp_cmd->cmd = cmd;
        kpdp_cmd->pdp_cmd = kmalloc(sizeof(KPDP_Command_t), GFP_KERNEL);
        copy_from_user(kpdp_cmd->pdp_cmd, (KPDP_Command_t *)arg, sizeof(KPDP_Command_t));

        KPDP_DEBUG(DBG_INFO, "CmdID:%d datalen:%d\n", kpdp_cmd->pdp_cmd->CmdID, (int)kpdp_cmd->pdp_cmd->datalen);

        if (0 != kpdp_cmd->pdp_cmd->datalen)
        {
            tdata = kmalloc(kpdp_cmd->pdp_cmd->datalen, GFP_KERNEL);
            if(NULL == tdata)
            {
                KPDP_DEBUG(DBG_ERROR, "tdata memory allocate fail!\n");
            }
            else
            {
                copy_from_user(tdata, kpdp_cmd->pdp_cmd->data, kpdp_cmd->pdp_cmd->datalen);
                KPDP_DEBUG(DBG_INFO, "tdata memory allocate success tdata:%p\n", kpdp_cmd->pdp_cmd->data);
                kpdp_cmd->pdp_cmd->data = tdata;
            }
        }
        else
        {
            KPDP_DEBUG(DBG_TRACE, "updp datalen is 0\n");
            kpdp_cmd->pdp_cmd->data = NULL;
        }

        mutex_lock(&gKpdpCmdQueue.mutex);
        list_add_tail(&kpdp_cmd->list, &gKpdpCmdQueue.list); 
        mutex_unlock(&gKpdpCmdQueue.mutex);
        queue_work(gKpdpCmdQueue.cmd_wq, &gKpdpCmdQueue.commandq);
        KPDP_DEBUG(DBG_INFO, "head cmd:%ld list:%p next:%p prev:%p\n", kpdp_cmd->cmd, &kpdp_cmd->list, kpdp_cmd->list.next, kpdp_cmd->list.prev);
    }
    return 0;
}
Exemple #19
0
/****************************************************************************
*
*  CAPI2_ClientInit(void);
*
*  Register IPC module.
*
***************************************************************************/
UInt32 KPDPCAPI2_ClientInit(void)
{
    UInt32 ret = 0;
    UInt8  clientID;
    Boolean bEnabled;
    
    clientID = CAPI2_SYS_RegisterClient(NULL, KPDP_RPC_RespCbk, KPDP_Capi2HandleAckCbk, KPDP_Capi2HandleFlowCtrl);
    bEnabled = RPC_EnableUnsolicitedMsgs(RPC_SYS_GetClientHandle(clientID), TRUE);

    KPDPSetClientID(clientID);
    
    KPDP_DEBUG(DBG_INFO, "CAPI2_ClientInit clientID:0x%x UnsolEnabled:%s\n", clientID, (bEnabled?"TRUE":"FALSE"));
    
    // initialize additional RPC interfaces needed for CIB
    // **FIXME** capirpc channel appears to no longer be required (only had SMS ME, which
    // isn't needed under Android)
//    KPDP_CapiRpc_Init();
    //KPDP_SysRpc_Init();
    //KPDP_ADCRpc_Init();
    
    return(ret);
}
Exemple #20
0
/**
   @fn Int32 KPDP_GetRsp()
*/
Int32 KPDP_GetRsp(struct file *filp, UInt32 cmd, UInt32 arg)
{
    Int32 rv = 0;
    KPDP_Param_t *priv = filp->private_data;
    KPDP_Response_t rsp;
    struct list_head *entry;
    KPDP_ResultQueue_t *buf_handle = NULL;
    UInt32    flags;

    if (copy_from_user(&rsp, (KPDP_Response_t*)arg, sizeof(rsp)))
    {
        KPDP_DEBUG(DBG_INFO, "KPDP_GetRsp() error in copy_from_user() \n");
        rv = -EFAULT;
        return rv;
    }

    /* We claim a mutex because we don't want two
       users getting something from the queue at a time.
       Since we have to release the spinlock before we can
       copy the data to the user, it's possible another
       user will grab something from the queue, too.  Then
       the messages might get out of order if something
       fails and the message gets put back onto the
       queue.  This mutex prevents that problem. */
    mutex_lock(&priv->recv_mutex);

    /* Grab the message off the list. */
    spin_lock_irqsave(&(priv->recv_lock), flags);
    if (list_empty(&(gKpdpResultQueue.list)))
    {
        spin_unlock_irqrestore(&(priv->recv_lock), flags);
        rv = -EAGAIN;
        KPDP_DEBUG(DBG_ERROR, "ERROR: KPDP Result List is empty %p\n", &(gKpdpResultQueue.list));
        goto recv_err;
    }
    entry = gKpdpResultQueue.list.next;
    buf_handle = list_entry(entry, KPDP_ResultQueue_t, list);
    list_del(entry);
    spin_unlock_irqrestore(&(priv->recv_lock), flags);

    if ((NULL == buf_handle->result_info.data) || (0 == buf_handle->result_info.datalen))
    {
        if ((NULL == buf_handle->result_info.data) != (0 == buf_handle->result_info.datalen))
        {
            KPDP_DEBUG(DBG_ERROR, "ERROR: KPDP Result data is Wrong %p, len %d\n", buf_handle->result_info.data, buf_handle->result_info.datalen);
            //Must enter data abort here
            goto recv_putback_on_err;
        }
    }

    rsp.result = buf_handle->result_info.result;
    rsp.CmdID = buf_handle->result_info.CmdID;
    rsp.datalen = buf_handle->result_info.datalen;

    if (0 != buf_handle->result_info.datalen)
    {
        if (copy_to_user(rsp.data, buf_handle->result_info.data, buf_handle->result_info.datalen))
        {
            rv = -EFAULT;
            KPDP_DEBUG(DBG_ERROR, "ERROR: KPDP copy response dara to user Fail\n");
            goto recv_putback_on_err;
        }
    }


    if (copy_to_user(arg, &rsp, sizeof(KPDP_Response_t)))
    {
        rv = -EFAULT;
        KPDP_DEBUG(DBG_ERROR, "ERROR: KPDP copy response infor to user Fail\n");
        goto recv_putback_on_err;
    }
    if (0 != buf_handle->result_info.datalen && buf_handle->result_info.data )
    {
        kfree( buf_handle->result_info.data );
    }
    kfree(buf_handle);
    buf_handle = NULL;

    if (false == list_empty(&(gKpdpResultQueue.list))) //not empty
    {
        KPDP_DEBUG(DBG_INFO, "rsp continue read list:%p, next:%p\n", &(gKpdpResultQueue.list), gKpdpResultQueue.list.next);
        rv = RESULT_NOT_EMPTY;
    }
    mutex_unlock(&priv->recv_mutex);
    return rv;

recv_putback_on_err:
    /* If we got an error, put the message back onto
       the head of the queue. */
    //KPDP_DEBUG(DBG_INFO, "recv_putback_on_err handle s_addr:%p, d_addr:%p\n", entry, &(gKpdpResultQueue.list));
    spin_lock_irqsave(&(priv->recv_lock), flags);
    list_add(entry, &(gKpdpResultQueue.list));
    spin_unlock_irqrestore(&(priv->recv_lock), flags);
    mutex_unlock(&priv->recv_mutex);
    return rv;
 
recv_err:
    mutex_unlock(&priv->recv_mutex);
    return rv;
}
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;
        }
    }
}
void KPDP_DeactivatePdpHandler(void *pdp_cmd, Kpdp_CAPI2Info_t *capi2_rsp)
{
    KPDP_CmdList_t *pdata = (KPDP_CmdList_t *)pdp_cmd;

    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:
        {
            char *cid = (char *)(pdata->pdp_cmd->data);
            UInt8 ContextID = (UInt8)(*cid - 0x30);
            UInt8 i;

            KPDP_DEBUG(DBG_INFO, "KPDP_DeactivatePdpHandler - length %d, Cid:%d \n", pdata->pdp_cmd->datalen, ContextID);
            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);
            for (i=0 ; i<BCM_NET_MAX_DUN_PDP_CNTXS ; i++)
            {
                if (ContextID == Kpdp_pdp_resp[pdata->pdp_cmd->SimId][i].cid) // To find the contextID in Kpdp_pdp_resp list, need to deactivate the context
                {
                    KPDP_DEBUG(DBG_INFO, "ReleaseDunPdpContext[%d]=%d \n", i, Kpdp_pdp_resp[pdata->pdp_cmd->SimId][i].cid);
                    break;
                }
                else if ((BCM_NET_MAX_DUN_PDP_CNTXS-1) == i) // Return finish state if can't find the contestID in Kpdp_pdp_resp list.
                {
                    KPDP_DEBUG(DBG_INFO, "Can't find corresponding cid = %d\n", ContextID);
                    pdata->handler_state = BCM_FinishCAPI2Cmd;
                    return;
                }
            }
            {
                CAPI2_PchExApi_SendPDPDeactivateReq( KPDPInitClientInfo(pdata->pdp_cmd->SimId), ContextID );
            }
            ReleaseDunPdpContext(pdata->pdp_cmd->SimId, ContextID);
            pdata->handler_state = BCM_RESPCAPI2Cmd;
        }
        break;

        case BCM_RESPCAPI2Cmd:
        {
        	   KPDP_DEBUG(DBG_INFO, "result:0x%x\n", capi2_rsp->result);
            if(RESULT_OK != capi2_rsp->result)
            {
                KPDP_DEBUG(DBG_ERROR, "PDPDeActivate Fail to SendPDPDeActivateReq \n");
                pdata->result = RESULT_ERROR;
                pdata->handler_state = BCM_ErrorCAPI2Cmd;
                break;
            }

            if(NULL != capi2_rsp->dataBuf)
            {
                PDP_SendPDPDeactivateReq_Rsp_t *rsp = (PDP_SendPDPDeactivateReq_Rsp_t *)capi2_rsp->dataBuf;
                KpdpPdpData_t *rdata = pdata->bcm_pdp_rsp;
                if(rsp->response != PCH_REQ_ACCEPTED)
                {
                    KPDP_DEBUG(DBG_ERROR, "PDPDeActivate Fail resp(1 accept) %d, cid %d\r\n", rsp->response, rsp->cid);
                    pdata->result = RESULT_ERROR;
                    rdata->cause = rsp->cause;
                    pdata->handler_state = BCM_ErrorCAPI2Cmd;
                    break;
                }

                rdata->cid = rsp->cid;
                KPDP_DEBUG(DBG_INFO, "PDP Deactivate Resp - cid %d \n", rsp->cid);

                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;
        }
    }
}
static void SendPAPOptions(SimNumber_t SimId, KpdpPdpContext_t* context)
{
    KPDP_DEBUG(DBG_INFO, "SendPAPOptions \r\n");
    CAPI2_PchExApi_BuildIpConfigOptions(KPDPInitClientInfo(SimId), context->username, context->password, REQUIRE_PAP);
}
Exemple #24
0
static int KPDP_Release(struct inode *inode, struct file *filp)
{
    KPDP_DEBUG(DBG_INFO, "KPDP_Release %s: major %d minor %d (pid %d)\n", __func__, imajor(inode), iminor(inode), current->pid);
    KPDP_DEBUG(DBG_INFO, "i_private=%p private_data=%p\n", inode->i_private, filp->private_data);
    return 0;
}