void link_PushPacket(struct link *l, struct ppp_mbuf *bp,/* struct bundle *b, */VOS_INT32 pri,
                VOS_UINT16 proto)
{
    PPP_ID                  usPppId     = (PPP_ID)(PPP_LINK_TO_ID(l));
    PPP_HDLC_CONFIG_STRU   *pstHdlcConfig;


    /* 把PPP协商包作为可维可测信息,IP包不做可维可测维护*/
    if (PROTO_IP != proto)
    {
        Ppp_MBufFrameMntnInfo(bp, proto, PPP_SEND_OUT_PROTOCOL_FRAME);
    }

    pstHdlcConfig = PPP_CONFIG(usPppId);

    if (VOS_NULL_PTR != pstHdlcConfig->pFunProcProtocolPacket)
    {
        pstHdlcConfig->pFunProcProtocolPacket(l, bp, pri, proto);
    }
    else
    {
        ppp_m_freem(bp);
        bp = VOS_NULL_PTR;

        PPP_MNTN_LOG(PS_PID_APP_PPP, 0, PS_PRINT_WARNING,
                     "PPP, link_PushPacket, WARNING, pFunProcProtocolPacket is NULL!\r\n");
    }

    return;
}
/*****************************************************************************
 函 数 名  : chap_Success
 功能描述  : 构造Success帧并发送
 输入参数  : l - PPP链接
 输出参数  : 无
 返 回 值  : 无
 调用函数  :
 被调函数  :

 修改历史      :
  1.日    期   : 2008年10月25日
    作    者   : liukai
    修改内容   : porting from BSD

*****************************************************************************/
static VOS_VOID chap_Success(struct link *l)
{
    struct authinfo *authp = &(l->chap.auth);
    const VOS_CHAR *pcMsg = "Welcome!!";    /* follow BSD use "Welcome!!" as message */

    /* Success body: */
    /*
     *  -------------
     * |   Message   |
     *  -------------
     */

    ChapOutput(l, CHAP_SUCCESS, authp->id, (VOS_UCHAR *)pcMsg, VOS_StrLen((VOS_CHAR *)pcMsg), VOS_NULL_PTR);

    l->lcp.auth_ineed = 0;    /* after Authentication, clear flag to authenticate peer */

    if (0 == l->lcp.auth_iwait)    /* auth_iwait: 0, authentication to peer is not complete or no need to authentication,
                                               !0, authentication to peer is complete */
    {
        /*
         * Either I didn't need to authenticate, or I've already been
         * told that I got the answer right.
         */
        chap_ReInit(&(l->chap));
        if (PHASE_AUTHENTICATE == l->phase)
        {
            l->phase = PHASE_NETWORK;
            l->ipcp.fsm.state = ST_CLOSED;
            fsm_Open(&(l->ipcp.fsm));
            PPP_MNTN_LOG(PS_PID_APP_PPP, 0, PS_PRINT_NORMAL, "goto ipcp stage!\r\n");
        }
    }

    return;
}    /* chap_Success */
VOS_INT32 link_ShowLayers(struct link *l/*struct cmdargs const *arg*/)
{
    /*  struct link *l = command_ChooseLink(arg);*/
    VOS_INT32 layer;

    for (layer = l->nlayers; layer; layer--)
    {
        PPP_MNTN_LOG(PS_PID_APP_PPP, 0, PS_PRINT_NORMAL, "%s%s");
    }
    if (l->nlayers)
    {
        PPP_MNTN_LOG(PS_PID_APP_PPP, 0, PS_PRINT_NORMAL, "\n");
    }

    return 0;
}
struct ppp_mbuf *
ppp_m_prepend(struct ppp_mbuf *bp, const void *ptr, VOS_INT32 len, VOS_INT32 extra)
{
  struct ppp_mbuf *head;

  if (bp && bp->m_offset) {
    if (bp->m_offset >= len) {
      bp->m_offset -= (VOS_INT16)len;
      bp->m_len += len;
      PS_MEM_CPY(PPP_MBUF_CTOP(bp), ptr, len);
      return bp;
    }
    len -= bp->m_offset;
    PS_MEM_CPY(bp + 1, (const VOS_CHAR *)ptr + len, bp->m_offset);
    bp->m_len += bp->m_offset;
    bp->m_offset = 0;
  }

  head = ppp_m_get(len + extra);

  if(head != VOS_NULL)
  {

      head->m_offset = (VOS_INT16)extra;
      head->m_len -= extra;
      if (ptr)
        PS_MEM_CPY(PPP_MBUF_CTOP(head), ptr, len);
      head->m_next = bp;
      return head;

  }

  PPP_MNTN_LOG(PS_PID_APP_PPP, 0, PS_PRINT_WARNING,"Failed to ppp_m_prepend\r\n");
  return bp;
}
Ejemplo n.º 5
0
VOS_UINT32 Ppp_SndPPPDisconnIndtoAT(VOS_UINT16 usPppId)
{
    AT_PPP_PROTOCOL_REL_IND_MSG_STRU    *pstMsg;
    VOS_UINT32                           ulLength;


    /* 可维可测信息上报*/
    Ppp_EventMntnInfo(usPppId, PPP_PROTOCOL_RELEASED_IND);

    if(PPP_MAX_ID_NUM < usPppId)
    {
        PPP_MNTN_LOG(PS_PID_APP_PPP, 0, PS_PRINT_ERROR,"Ppp_SndPPPDisconnIndtoAT usPppId Wrong!\r\n");
        return VOS_ERR;
    }

    /*向AT模块发送AT_PPP_RELEASE_IND_MSG*/
    ulLength    = sizeof(AT_PPP_PROTOCOL_REL_IND_MSG_STRU) - VOS_MSG_HEAD_LENGTH;
    pstMsg      = (AT_PPP_PROTOCOL_REL_IND_MSG_STRU *)PS_ALLOC_MSG(PS_PID_APP_PPP, ulLength);
    if (VOS_NULL_PTR == pstMsg)
    {
        /*打印出错信息---申请消息包失败:*/
        PPP_MNTN_LOG(PS_PID_APP_PPP, 0, PS_PRINT_ERROR,"Ppp_SndPPPDisconnIndtoAT : PS_ALLOC_MSG Failed!\r\n");
        return VOS_ERR;
    }
    /*填写消息头:*/
    pstMsg->MsgHeader.ulSenderCpuId   = VOS_LOCAL_CPUID;
    pstMsg->MsgHeader.ulSenderPid     = PS_PID_APP_PPP;
    pstMsg->MsgHeader.ulReceiverCpuId = VOS_LOCAL_CPUID;
    pstMsg->MsgHeader.ulReceiverPid   = WUEPS_PID_AT;
    pstMsg->MsgHeader.ulLength        = ulLength;

    pstMsg->MsgHeader.ulMsgName       = AT_PPP_PROTOCOL_REL_IND_MSG;
    /*填写消息体:*/
    pstMsg->usPppId                   = usPppId;

    /*发送该消息*/
    if (VOS_OK != PS_SEND_MSG(PS_PID_APP_PPP, pstMsg))
    {
        /*打印警告信息---发送消息失败:*/
        PPP_MNTN_LOG(PS_PID_APP_PPP, 0, PS_PRINT_ERROR,"Ppp_SndPPPDisconnIndtoAT : PS_SEND_MSG Failed!");
        return VOS_ERR;
    }

    return VOS_OK;
}
VOS_INT32 link_Stack(struct link *l, struct layer *layer)
{
  if (l->nlayers == sizeof l->layer / sizeof l->layer[0]) {
    PPP_MNTN_LOG(PS_PID_APP_PPP, 0, PS_PRINT_WARNING,
        "Oops, cannot stack a layer\r\n");
    return 0;
  }
  l->layer[l->nlayers++] = layer;
  return 1;
}
VOS_INT32
ppp_mbuf_Show(VOS_VOID)
{
  VOS_INT32 i;

  PPP_MNTN_LOG(PS_PID_APP_PPP, 0, PS_PRINT_NORMAL,"Fragments (octets) in use:\r\n");
  for (i = 0; i < MB_MAX; i += 2)
    PPP_MNTN_LOG(PS_PID_APP_PPP, 0, PS_PRINT_NORMAL, "%10.10s: %04lu (%06lu)\r\n");

  if (i == MB_MAX)
    PPP_MNTN_LOG(PS_PID_APP_PPP, 0, PS_PRINT_NORMAL, "%10.10s: %04lu (%06lu)\r\n"/*,
                  mbuftype(i), (VOS_UINT32)MemMap[i].fragments,
                  (VOS_UINT32)MemMap[i].octets*/);

  PPP_MNTN_LOG(PS_PID_APP_PPP, 0, PS_PRINT_NORMAL, "Mallocs: %qu,   Frees: %qu\r\n"/*,
                mbuf_Mallocs, mbuf_Frees*/);

  return 0;
}
void
link_ReportProtocolStatus(struct link *l/*, struct prompt *prompt*/)
{
    VOS_INT32 i;

    PPP_MNTN_LOG(PS_PID_APP_PPP, 0, PS_PRINT_NORMAL, "Protocol  in out\r\n");
    for (i = 0; i < NPROTOSTAT; i++)
    {
        PPP_MNTN_LOG(PS_PID_APP_PPP, 0, PS_PRINT_NORMAL, "   %-9s: %8lu, %8lu\r\n"/*,
            ProtocolStat[i].name, l->proto_in[i], l->proto_out[i]*/);
        if ((i % 2) == 0)
        {
            PPP_MNTN_LOG(PS_PID_APP_PPP, 0, PS_PRINT_NORMAL, "\n");
        }
    }
    if (!(i % 2))
    {
        PPP_MNTN_LOG(PS_PID_APP_PPP, 0, PS_PRINT_NORMAL, "\n");
    }
}
void
SendPapCode(struct link *l, VOS_CHAR code, VOS_CHAR *message)
{
  struct fsmheader lh;
  struct ppp_mbuf *bp;
  VOS_CHAR *cp;
  VOS_UINT32 plen, mlen;


  lh.code = code;
  lh.id = l->pap.auth.id;
  mlen = VOS_StrNLen(message,20);
  plen = mlen + 1;
  lh.length = (VOS_UINT16)VOS_HTONS(plen + sizeof(struct fsmheader));
  bp = ppp_m_get(plen + PPP_RECIEVE_RESERVE_FOR_HEAD + PPP_RECIEVE_RESERVE_FOR_TAIL + sizeof(struct fsmheader));

  if(bp == VOS_NULL)
  {
        PPP_MNTN_LOG(PS_PID_APP_PPP, 0, PS_PRINT_WARNING, "no mbuf");
    return;
  }
    /*预留头部*/
    bp->m_offset = PPP_RECIEVE_RESERVE_FOR_HEAD;

    /*头部与尾部都留出来了*/
    bp->m_len = plen + sizeof(struct fsmheader);

  PS_MEM_CPY(PPP_MBUF_CTOP(bp), &lh, sizeof(struct fsmheader));
  cp = PPP_MBUF_CTOP(bp) + sizeof(struct fsmheader);
  /*
   * If our message is longer than 255 bytes, truncate the length to
   * 255 and send the entire message anyway.  Maybe the other end will
   * display it... (see pap_Input() !)
   */
  *cp++ = (VOS_CHAR)(mlen > 255 ? 255 : mlen);
  PS_MEM_CPY(cp, message, mlen);
  PPP_MNTN_LOG(PS_PID_APP_PPP, 0, PS_PRINT_NORMAL, "Pap Output\r\n");

  link_PushPacket(l, bp,/* authp->physical->dl->bundle,*/
                  LINK_QUEUES(l) - 1, PROTO_PAP);
}
Ejemplo n.º 10
0
VOS_UINT32 PPP_InitHdlcConfig(PPP_ID usPppId)
{
    PPP_HDLC_CONFIG_STRU               *pstHdlcConfig;


    if ((usPppId == 0) || (PPP_MAX_ID_NUM < usPppId))
    {
        return VOS_ERR;
    }

    pstHdlcConfig = PPP_CONFIG(usPppId);

    if (PPP_HDLC_BY_SOFTWARE == g_ulHDLCConfig)
    {
        pstHdlcConfig->pFunProcData            = PPP_HDLC_SOFT_ProcData;
        pstHdlcConfig->pFunProcProtocolPacket  = PPP_HDLC_SOFT_ProcProtocolPacket;
        pstHdlcConfig->pFunDisable             = VOS_NULL_PTR;
        pstHdlcConfig->pFunProcAsFrmData       = VOS_NULL_PTR;

        PPP_MNTN_LOG(PS_PID_APP_PPP, 0, PS_PRINT_WARNING,
                     "\r\nPPP, PPP_InitHdlcConfig, INFO, Soft HDLC.\r\n");
    }
    else
    {
        pstHdlcConfig->pFunProcData            = PPP_HDLC_HARD_ProcData;
        pstHdlcConfig->pFunProcProtocolPacket  = PPP_HDLC_HARD_ProcProtocolPacket;
        pstHdlcConfig->pFunDisable             = PPP_HDLC_HARD_Disable;
        pstHdlcConfig->pFunProcAsFrmData       = PPP_HDLC_HARD_ProcAsFrmPacket;

        PPP_HDLC_HARD_SetUp(usPppId);

        PPP_MNTN_LOG(PS_PID_APP_PPP, 0, PS_PRINT_WARNING,
                     "\r\nPPP, PPP_InitHdlcConfig, INFO, Hard HDLC.\r\n");
    }

    return VOS_OK;
}
void link_SequenceQueue(struct link *l)
{
  struct ppp_mqueue *queue, *highest;

  PPP_MNTN_LOG(PS_PID_APP_PPP, 0, PS_PRINT_NORMAL, "link_SequenceQueue\r\n");

  highest = LINK_HIGHQ(l);
  for (queue = l->Queue; queue < highest; queue++)
  {
    while (queue->len)
    {
        ppp_m_enqueue(highest, ppp_m_dequeue(queue));
    }
  }
}
Ejemplo n.º 12
0
VOS_UINT32 PPP_RcvAtCtrlOperEvent(VOS_UINT16 usPppId, PPP_AT_CTRL_OPER_TYPE_ENUM_UINT32 ulCtrlOperType)
{
    PPP_AT_CTRL_OPERATION_MSG *pSndMsg;

    if(PPP_AT_CTRL_BUTT <= ulCtrlOperType)
    {
        PPP_MNTN_LOG1(PS_PID_APP_PPP, 0, PS_PRINT_ERROR,
                "PPP_RcvAtCtrlOperEvent:ulCtrlOperType ERROR!",(VOS_INT32)ulCtrlOperType);
        return VOS_ERR;
    }

    pSndMsg = (PPP_AT_CTRL_OPERATION_MSG *)PS_ALLOC_MSG(PS_PID_APP_PPP, sizeof(PPP_AT_CTRL_OPERATION_MSG) - VOS_MSG_HEAD_LENGTH);

    if (VOS_NULL_PTR == pSndMsg)
    {
        PPP_MNTN_LOG(PS_PID_APP_PPP, 0, PS_PRINT_WARNING,
            "PPP, PPP_RcvAtCtrlOperEvent, WARNING, Alloc msg fail!\r\n");
        return VOS_ERR;
    }

    pSndMsg->ulReceiverCpuId    = VOS_LOCAL_CPUID;
    pSndMsg->ulReceiverPid      = PS_PID_APP_PPP;
    pSndMsg->ulMsgType          = PPP_AT_CTRL_OPERATION;
    pSndMsg->usPppId            = usPppId;
    pSndMsg->ulCtrlOpType       = ulCtrlOperType;

    /*发送该消息:*/
    if ( VOS_OK != PS_SEND_MSG(PS_PID_APP_PPP, pSndMsg) )
    {
        PPP_MNTN_LOG(PS_PID_APP_PPP, 0, PS_PRINT_WARNING,
                     "PPP, PPP_RcvAtCtrlOperEvent, WARNING, Send msg fail!\r\n");
        return VOS_ERR;
    }

    return VOS_OK;
}
void
pap_Success(struct link *l)
{
#if 0/*fanzhibin f49086 delete it*/
  struct bundle *bundle = authp->physical->dl->bundle;

  datalink_GotAuthname(authp->physical->dl, authp->in.name);
#ifndef NORADIUS
  if (*bundle->radius.cfg.file && bundle->radius.repstr)
    SendPapCode(authp, PAP_ACK, bundle->radius.repstr);
  else
#endif
#endif
    SendPapCode(l, PAP_ACK, "Greetings!!");
#if 0/*fanzhibin f49086 delete it*/
/*下面这句在改造的时候要添进去*/
  authp->physical->link.lcp.auth_ineed = 0;
  if (Enabled(bundle, OPT_UTMP))
    physical_Login(authp->physical, authp->in.name);
/*下面这句在改造的时候要添进去*/
  if (authp->physical->link.lcp.auth_iwait == 0)
    /*
     * Either I didn't need to authenticate, or I've already been
     * told that I got the answer right.
     */
    datalink_AuthOk(authp->physical->dl);
  #endif
/*fanzhibin f49086 add it begin*/
  l->lcp.auth_ineed = 0;
  if(l->lcp.auth_iwait == 0)    /* auth_iwait: 0, authentication to peer is not complete or no need to authentication,
                                              !0, authentication to peer is complete */
    {
        if (PHASE_AUTHENTICATE == l->phase)
        {
          l->phase = PHASE_NETWORK;
          l->ipcp.fsm.state = ST_CLOSED;
          fsm_Open(&(l->ipcp.fsm));
          PPP_MNTN_LOG(PS_PID_APP_PPP, 0, PS_PRINT_NORMAL, "goto ipcp stage!\r\n");
        }
    }

/*fanzhibin f49086 add it end*/

}
/*****************************************************************************
 函 数 名  : ChapOutput
 功能描述  : 构造CHAP帧并发送
 输入参数  : l - PPP链接
             code - 待填写到头部的Code值
             id - 待填写到头部的Identifier值
             ptr - 待填写的CHAP数据
             count - 待填写的CHAP数据的长度, 单位: 字节
             text - 字符串, 用于日志
 输出参数  : 无
 返 回 值  : NULL
 调用函数  :
 被调函数  :
 说    明  : 不对ptr与code进行组合检查, 如code为某值时, ptr不应为空等等,
             因为此函数为一通用函数, 支持生成所有的CHAP帧, 并能扩展为支持
             MS-CHAP帧等, 各种code, ptr组合情况众多, 一切相关检查交由外部
             调用者来完成

 修改历史      :
  1.日    期   : 2008年10月24日
    作    者   : liukai
    修改内容   : porting from BSD

*****************************************************************************/
VOS_VOID ChapOutput(struct link *l, VOS_INT32 code, VOS_CHAR id,
                    const VOS_UCHAR *ptr, VOS_UINT32 count, const VOS_CHAR *text)
{
    VOS_UINT32 len;    /* length of a CHAP frame */
    struct fsmheader lh;
    struct ppp_mbuf *bp;

    len = sizeof(struct fsmheader) + count;
    lh.code = (VOS_CHAR)code;
    lh.id = id;
    lh.length = (VOS_UINT16)VOS_HTONS(len);
    bp = ppp_m_get((VOS_INT32)len);

    if (VOS_NULL_PTR == bp)
    {
        PPP_MNTN_LOG(PS_PID_APP_PPP, 0, PS_PRINT_WARNING, "no mbuf\r\n");
        return;
    }

    PS_MEM_CPY(PPP_MBUF_CTOP(bp), &lh, sizeof(struct fsmheader));
    if ((count > 0) && (VOS_NULL_PTR != ptr))
    {
        PS_MEM_CPY(PPP_MBUF_CTOP(bp) + sizeof(struct fsmheader), ptr, count);
    }

    if (VOS_NULL_PTR == text)
    {
        PPP_MNTN_LOG1(PS_PID_APP_PPP, 0, PS_PRINT_NORMAL, "Chap Output: code %d\r\n", code);
    }
    else
    {
        PPP_MNTN_LOG1(PS_PID_APP_PPP, 0, PS_PRINT_NORMAL,"Chap Output: code %d with text\r\n", code);
    }

    /* now a CHAP frame is ready */
    link_PushPacket(l, bp, LINK_QUEUES(l) - 1, PROTO_CHAP);

    return;
}    /* ChapOutput */
/*****************************************************************************
 函 数 名  : chap_Input
 功能描述  : 收到CHAP帧的处理入口函数
 输入参数  : l - PPP链接
             pstMem - 收到的CHAP帧
 输出参数  : 无
 返 回 值  : NULL
 调用函数  :
 被调函数  :

 修改历史      :
  1.日    期   : 2008年10月24日
    作    者   : liukai
    修改内容   : porting from BSD

*****************************************************************************/
PPP_ZC_STRU *chap_Input(struct link *l, PPP_ZC_STRU *pstMem)
{
    struct chap *chap;
    VOS_INT32 len;
    VOS_UCHAR alen;    /* answer length: challenge or response body length */
    struct ppp_mbuf *bp;
    VOS_UCHAR aucHashValue[MD5DIGESTSIZE];

    bp = ppp_m_get_from_ttfmem(pstMem);
    PPP_MemFree(pstMem);

    if (VOS_NULL_PTR == bp)
    {
        return VOS_NULL_PTR;
    }

    if (VOS_NULL_PTR == l) {
        PPP_MNTN_LOG(PS_PID_APP_PPP, 0, PS_PRINT_WARNING, "Chap Input: Not a physical link - dropped\r\n");
        ppp_m_freem(bp);
        return VOS_NULL_PTR;
    }

    if ((PHASE_NETWORK != l->phase) &&
            (PHASE_AUTHENTICATE != l->phase)) {
        PPP_MNTN_LOG(PS_PID_APP_PPP, 0, PS_PRINT_NORMAL, "Unexpected Chap input - dropped\r\n");
        ppp_m_freem(bp);
        return VOS_NULL_PTR;
    }

    chap = &(l->chap);
    if ((VOS_NULL_PTR == (bp = auth_ReadHeader(&chap->auth, bp))) &&
            (0 == VOS_NTOHS(chap->auth.in.hdr.length)))
    {
        PPP_MNTN_LOG(PS_PID_APP_PPP, 0, PS_PRINT_WARNING, "Chap Input: Truncated header\r\n");
    }
    else if ((0 == chap->auth.in.hdr.code) || ((VOS_UINT8)(chap->auth.in.hdr.code) > MAXCHAPCODE))
    {
        PPP_MNTN_LOG1(PS_PID_APP_PPP, 0, LOG_LEVEL_WARNING,
                      "Chap Input: Bad CHAP code %d !\r\n", chap->auth.in.hdr.code);
    }
    else {
        len = ppp_m_length(bp);

        /* Identifier of rx-ed Response, Success, Fail should match Challenge tx-ed */
        if ((CHAP_CHALLENGE != chap->auth.in.hdr.code) &&
                (chap->auth.id != chap->auth.in.hdr.id)) {
            /* Wrong conversation dude ! */
            PPP_MNTN_LOG3(PS_PID_APP_PPP, 0, PS_PRINT_NORMAL,
                          "Chap Input: code <1> dropped (got id <2> not equal to previous id <3>)\r\n",
                          chap->auth.in.hdr.code, chap->auth.in.hdr.id, chap->auth.id);
            ppp_m_freem(bp);
            return VOS_NULL_PTR;
        }
        chap->auth.id = chap->auth.in.hdr.id;    /* We respond with this id */

        if (CHAP_CHALLENGE == chap->auth.in.hdr.code)    /* rx-ed challenge */
        {
            bp = ppp_mbuf_Read(bp, &alen, 1);    /* fetch length of peer's challenge */
            len -= (alen + 1);    /* after this step, len is length of peer's name */
            if (len < 0) {
                PPP_MNTN_LOG2(PS_PID_APP_PPP, 0, LOG_LEVEL_WARNING,
                              "Chap Input: Truncated challenge (len %d, alen %d)!\r\n", len, alen);
                ppp_m_freem(bp);
                return VOS_NULL_PTR;
            }
            if (AUTHLEN < len)
            {
                PPP_MNTN_LOG2(PS_PID_APP_PPP, 0, LOG_LEVEL_WARNING,
                              "Chap Input: name of challenge too long (len %d, alen %d)!\r\n", len, alen);
                ppp_m_freem(bp);
                return VOS_NULL_PTR;
            }
            if (CHAPCHALLENGELEN < alen)
            {
                PPP_MNTN_LOG1(PS_PID_APP_PPP, 0, LOG_LEVEL_WARNING,
                              "Chap Input: challenge too long (len %d)!\r\n", alen);
                ppp_m_freem(bp);
                return VOS_NULL_PTR;
            }

            *chap->challenge.peer = alen;
            bp = ppp_mbuf_Read(bp, chap->challenge.peer + 1, alen);    /* record peer's challenge */
            bp = auth_ReadName(&chap->auth, bp, len);    /* record peer's name */

            if (*chap->auth.in.name)    /* challenge with name */
            {
                PPP_MNTN_LOG2(PS_PID_APP_PPP, 0, LOG_LEVEL_WARNING,
                              "Chap Input: challenge (len %d, alen %d) with name\r\n",
                              len, alen);
            }
            else    /* without name */
            {
                PPP_MNTN_LOG2(PS_PID_APP_PPP, 0, LOG_LEVEL_WARNING,
                              "Chap Input: challenge (len %d, alen %d) without name\r\n",
                              len, alen);
            }

            chap_Respond(l, "HUAWEI_CHAP_CLNT");    /* we always use "HUAWEI_CHAP_CLNT" as Name of Response */
        }    /* end of rx-ed challenge */
        else if (CHAP_RESPONSE == chap->auth.in.hdr.code)    /* rx-ed response */
        {
            bp = ppp_mbuf_Read(bp, &alen, 1);    /* read HASH-Size */
            if (MD5DIGESTSIZE != alen)    /* as just support MD5, must be 16 octets */
            {
                PPP_MNTN_LOG1(PS_PID_APP_PPP, 0, LOG_LEVEL_WARNING,
                              "Chap Input: Hash-Size %f is not correct !\r\n", alen);
                ppp_m_freem(bp);
                return VOS_NULL_PTR;
            }
            len -= (alen + 1);    /* after this step, len is length of Name Field */
            if (len < 0) {
                PPP_MNTN_LOG2(PS_PID_APP_PPP, 0, LOG_LEVEL_WARNING,
                              "Chap Input: Truncated response (len %d, alen %d)!\r\n", len, alen);
                ppp_m_freem(bp);
                return VOS_NULL_PTR;
            }
            if (AUTHLEN < len)
            {
                PPP_MNTN_LOG2(PS_PID_APP_PPP, 0, LOG_LEVEL_WARNING,
                              "Chap Input: name of response too long (len %d, alen %d)!\r\n", len, alen);
                ppp_m_freem(bp);
                return VOS_NULL_PTR;
            }

            bp = ppp_mbuf_Read(bp, aucHashValue, MD5DIGESTSIZE);    /* cut HASH value */
            bp = auth_ReadName(&chap->auth, bp, len);

            if (*chap->auth.in.name)
            {
                PPP_MNTN_LOG2(PS_PID_APP_PPP, 0, PS_PRINT_NORMAL,"Chap Input: response (len <1>, alen <2>) with name\r\n",
                              len, alen);
            }
            else
            {
                PPP_MNTN_LOG2(PS_PID_APP_PPP, 0, PS_PRINT_NORMAL,"Chap Input: response (len <1>, alen <2>) without name\r\n",
                              len, alen);
            }

            if (PHASE_AUTHENTICATE == l->phase)    /* 需要注意只备份在认证阶段中与challenge id匹配的response */
            {
                ChapBufferResponsePacket(chap, MD5DIGESTSIZE, aucHashValue, len);
            }

            chap_Success(l);

            /*
               Moves code to here as the last step of dealing with response by liukai,
               it should stop authentication timer after authentication pass or fail.
               Stops timer at first, a response frame format is not correct and discards it(way of BSD),
               UE has no chance to send challenge again
            */
            auth_StopTimer(&(chap->auth));
        }    /* end of rx-ed response */
        else if (CHAP_SUCCESS == chap->auth.in.hdr.code)    /* rx-ed success */
        {
            /* chap->auth.in.name is already set up at CHALLENGE time, need NOT to print again */
            if (0 < len)
            {
                PPP_MNTN_LOG(PS_PID_APP_PPP, 0, PS_PRINT_NORMAL, "Chap Input: success with message\r\n");
            }
            else
            {
                PPP_MNTN_LOG(PS_PID_APP_PPP, 0, PS_PRINT_NORMAL, "Chap Input: success without message\r\n");
            }

            if (PROTO_CHAP == l->lcp.auth_iwait) {
                l->lcp.auth_iwait = 0;
                if (0 == l->lcp.auth_ineed)    /* auth_ineed: 0, authentication by peer is not complete or no need to authentication,
                                                       !0, authentication by peer is complete */
                {
                    /*
                     * We've succeeded in our ``login''
                     * If we're not expecting  the peer to authenticate (or he already
                     * has), proceed to network phase.
                     */
                    chap_ReInit(&(l->chap));
                    if (PHASE_AUTHENTICATE == l->phase)
                    {
                        l->phase = PHASE_NETWORK;
                        l->ipcp.fsm.state = ST_CLOSED;
                        fsm_Open(&(l->ipcp.fsm));
                        PPP_MNTN_LOG(PS_PID_APP_PPP, 0, PS_PRINT_NORMAL, "goto ipcp stage!\r\n");
                    }
                }
            }
        }    /* end of rx-ed success */
        else    /* rx-ed fail */
        {
            /* chap->auth.in.name is already set up at CHALLENGE time, need NOT to print again */
            if (0 < len)
            {
                PPP_MNTN_LOG(PS_PID_APP_PPP, 0, PS_PRINT_NORMAL, "Chap Input: fail with message\r\n");
            }
            else
            {
                PPP_MNTN_LOG(PS_PID_APP_PPP, 0, PS_PRINT_NORMAL, "Chap Input: fail without message\r\n");
            }

            chap_Cleanup(&(l->chap));
            l->phase = PHASE_TERMINATE;
            fsm_Close(&(l->lcp.fsm));
            PPP_MNTN_LOG(PS_PID_APP_PPP, 0, PS_PRINT_NORMAL, "goto lcp stage!\r\n");
        }    /* end of rx-ed fail */
    }

    ppp_m_freem(bp);
    return VOS_NULL_PTR;
}    /* chap_Input */
PPP_ZC_STRU *
pap_Input(/*struct bundle *bundle,*/ struct link *l, PPP_ZC_STRU *pstMem)
{
/*  struct physical *p = link2physical(l);*/
#if 0 /* delete for transplant */
  VOS_CHAR nlen, *key;
#endif

  struct authinfo *authp =/* &p->dl*/&(l->pap.auth);
  VOS_CHAR nlen;
  VOS_UINT8 klen;
  const VOS_CHAR *txt;
  VOS_INT32 txtlen;
  struct ppp_mbuf *bp;


  bp = ppp_m_get_from_ttfmem(pstMem);
  PPP_MemFree(pstMem);

  if (VOS_NULL_PTR == bp)
  {
    return VOS_NULL_PTR;
  }

  if (l == VOS_NULL_PTR) {
    PPP_MNTN_LOG(PS_PID_APP_PPP, 0, PS_PRINT_WARNING, "pap input, Not a physical link - dropped\r\n");
    ppp_m_freem(bp);
    return VOS_NULL_PTR;
  }

  if (/*bundle_Phase(bundle)*/ l->phase!= PHASE_NETWORK &&
      /*bundle_Phase(bundle)*/ l->phase!= PHASE_AUTHENTICATE) {
    PPP_MNTN_LOG(PS_PID_APP_PPP, 0, PS_PRINT_NORMAL, "Unexpected pap input - dropped\r\n");
    ppp_m_freem(bp);
    return VOS_NULL_PTR;
  }

  if ((bp = auth_ReadHeader(authp, bp)) == VOS_NULL_PTR &&
      VOS_NTOHS(authp->in.hdr.length) == 0) {
    PPP_MNTN_LOG(PS_PID_APP_PPP, 0, PS_PRINT_WARNING, "Pap Input: Truncated header\r\n");
    return VOS_NULL_PTR;
  }

  if (authp->in.hdr.code == 0 || authp->in.hdr.code > MAXPAPCODE) {
    PPP_MNTN_LOG1(PS_PID_APP_PPP, 0, LOG_LEVEL_WARNING,
                  "Bad PAP code: %d", authp->in.hdr.code);
    ppp_m_freem(bp);
    return VOS_NULL_PTR;
  }

  if (authp->in.hdr.code != PAP_REQUEST && authp->id != authp->in.hdr.id)
    {
    /* Wrong conversation dude ! */
    PPP_MNTN_LOG(PS_PID_APP_PPP, 0, PS_PRINT_WARNING, "pap input, dropped (got id not equal to previous id)\r\n");
    ppp_m_freem(bp);
    return VOS_NULL_PTR;
    }
  authp->id = authp->in.hdr.id;        /* We respond with this id */

  /*fanzhibin f49086 add it begin*/
  if (authp->in.hdr.code == PAP_REQUEST)
  {
    /*将config req报文头部拷贝到缓存中*/
    PS_MEM_CPY(l->pap.RecordData.BufRequest,&(authp->in.hdr),sizeof(authp->in.hdr));

    ppp_mbuf_View(bp,(l->pap.RecordData.BufRequest + sizeof(authp->in.hdr)),
                    VOS_NTOHS(authp->in.hdr.length) - sizeof(authp->in.hdr));
    l->pap.RecordData.LenOfRequest = VOS_NTOHS(authp->in.hdr.length);

  }
  /*fanzhibin f49086 add it end*/



  if (bp) {
    bp = ppp_mbuf_Read(bp, &nlen, 1);
    if (authp->in.hdr.code == PAP_ACK) {
      /*
       * Don't restrict the length of our acknowledgement freetext to
       * nlen (a one-byte length).  Show the rest of the ack packet
       * instead.  This isn't really part of the protocol.....
       */
      bp = ppp_m_pullup(bp);
      txt = PPP_MBUF_CTOP(bp);
      txtlen = ppp_m_length(bp);
    } else {
      bp = auth_ReadName(authp, bp, nlen);
      txt = authp->in.name;
      txtlen = VOS_StrNLen(authp->in.name,AUTHLEN);
      PPP_MNTN_LOG(PS_PID_APP_PPP, 0, PS_PRINT_NORMAL, "username:"******"";
    txtlen = 0;
  }

  PPP_MNTN_LOG(PS_PID_APP_PPP, 0, PS_PRINT_NORMAL, "\r\nPap Input\r\n");

  switch (authp->in.hdr.code) {
    case PAP_REQUEST:
      if (bp == VOS_NULL_PTR) {
        PPP_MNTN_LOG(PS_PID_APP_PPP, 0, PS_PRINT_NORMAL, "Pap Input: No key given !\r\n");
        break;
      }
      bp = ppp_mbuf_Read(bp, &klen, 1);
      if (ppp_m_length(bp) < klen) {
        PPP_MNTN_LOG(PS_PID_APP_PPP, 0, PS_PRINT_WARNING, "Pap Input: Truncated key !\r\n");
        break;
      }

#if 0/*fanzhibin f49086 delete it*/
      if ((key = VOS_MemAlloc(PS_PID_APP_PPP, DYNAMIC_DOPRA_MEM_PT,klen+1)) == VOS_NULL_PTR) {
        PS_LOG(PS_PID_APP_PPP, 0, PS_PRINT_ERROR, "Pap Input: Out of memory !\n");
        break;
      }
      bp = ppp_mbuf_Read(bp, key, klen);
      key[klen] = '\0';


#ifndef NORADIUS
      if (*bundle->radius.cfg.file) {
        if (!radius_Authenticate(&bundle->radius, authp, authp->in.name,
                                 key, strlen(key), VOS_NULL_PTR, 0))
          pap_Failure(authp);
      } else
#endif
/*下面这句在改造的时候要添进去*/
      if (auth_Validate(bundle, authp->in.name, key, p))
        pap_Success(authp);
      else
        pap_Failure(authp);

      VOS_MemFree(PS_PID_APP_PPP,key);
#endif

/*fanzhibin f49086 add it begin*/
      if (klen > sizeof l->pap.RecordData.password- 1)
      {
        PPP_MNTN_LOG1(PS_PID_APP_PPP, 0, LOG_LEVEL_WARNING,
                      "auth_ReadPassword: PassWord too long,len= %d", klen);
      }
      else {
        if (klen > ppp_m_length(bp))
        {
          PPP_MNTN_LOG1(PS_PID_APP_PPP, 0, LOG_LEVEL_WARNING,
                        "auth_ReadPassword: Short packet, pass_len = %d", klen);
        }
        else {
          bp = ppp_mbuf_Read(bp, l->pap.RecordData.password, klen);
          l->pap.RecordData.password[klen] = '\0';
          PPP_MNTN_LOG(PS_PID_APP_PPP, 0, PS_PRINT_NORMAL, "password:");
          PPP_MNTN_LOG(PS_PID_APP_PPP, 0, PS_PRINT_NORMAL, l->pap.RecordData.password);

        }
      }

      pap_Success(l);
/*fanzhibin f49086 add it end*/

      break;

    case PAP_ACK:
#if 0/*fanzhibin f49086 delete it*/
      auth_StopTimer(authp);
      if (p->link.lcp.auth_iwait == PROTO_PAP) {
        p->link.lcp.auth_iwait = 0;
        if (p->link.lcp.auth_ineed == 0)
          /*
           * We've succeeded in our ``login''
           * If we're not expecting  the peer to authenticate (or he already
           * has), proceed to network phase.
           */
          datalink_AuthOk(p->dl);
      }
#endif
      break;

    case PAP_NAK:

#if 0/*fanzhibin f49086 delete it*/
      auth_StopTimer(authp);
      datalink_AuthNotOk(p->dl);
#endif

      break;
  }

  ppp_m_freem(bp);
  return VOS_NULL_PTR;
}