⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 t38fax.c

📁 m80320 VoIP DSP驱动源码
💻 C
📖 第 1 页 / 共 4 页
字号:
        default:
            return(ERROR_ARGUMENT);
    }
    /*-------------------
        Parameter 1 —Channel ID of Channel
            0x0000–0x00FE = 1 of 254 possible Channel IDs
            0x00FF = Reserved for Supervisor
            0x0100–0xFFFF = Reserved
        Parameter 2 —New Channel Type
            0x0000 = Reserved
            0x0001 = Data (Analog Data/Fax Modem, V.110, V.120)
            0x0002 = Voice over IP (VoIP)
            0x0003–0x0006 = Reserved
            0x0007 = Fax over IP (FoIP-T.38)
            0x0008 = Voice over ATM (VoATM)
            0x0009–0xFFFF = Reserved
        Parameter 3 —TimeSlot number    
    */
    result = sendSuperMsg(CMD_CHANGE_TYPE | 0xFF,  (m_port[portNo].Channel)%PORTS_OF_CHIP, mode, (m_port[portNo].Channel)%PORTS_OF_CHIP, portNo);
    if (SENDTOM803xxOK == result)
    {    
        /*printf("Send MSG of Switch to %s success!\n", type == SWITCH_TO_T38_FAX? "T38 Fax":"Voice");*/
        /*added by fengya*/
        if(m_port[portNo].CallType == LFXS_CALLTYPE_IN)
        {
            faxGDebug(/*faxrelaymsg |*/ faxrelaymsgcalled, "Send MSG of Switch to %s success!\n", type == SWITCH_TO_T38_FAX? "T38 Fax":"Voice");
        }
        else if(m_port[portNo].CallType == LFXS_CALLTYPE_OUT)
        {
            faxGDebug(/*faxrelaymsg |*/ faxrelaymsgcalling, "Send MSG of Switch to %s success!\n", type == SWITCH_TO_T38_FAX? "T38 Fax":"Voice");
        }

    }

    return (result);    
}


/*-----------------------------
* setT38FaxOperation - 向发送队列增加消息,
*
* Description:
* 
* Argument:
*          portNo   -- No. Of The M803xx Port  
*
* Return:
*    
* Modified history
*------------------------------
* 2006-3-18 09:13 ZhengaQishan Created.
*
**/
UINT16 gTmpT38FaxArg1 = 0;
UINT16 gTmpT38FaxArg2 = 0x00;
int setT38FaxOperation(UINT8 portNo)
{
    /*UINT16 tmpValue;*/
    UINT16 InCmd;
    int  result = SENDTOM803xxOK;
    UINT16 t38FaxOperValue = 0;
    UINT16 t38FaxSignalLevel = 0;
    T38_FAX_ARG_T *pFaxOper = (T38_FAX_ARG_T *)NULL;

    pFaxOper = &(gpT38FaxParameter[portNo]->t38FaxArg.chipArg);
            
    /*T38 Fax 接口参数解析*/
    /*----------------------
    Bit(s)               Definition
    15:14       T.38 packet loss concealment:
                0 = No T.38 packet loss concealment (default)
                1 = Packet loss concealment enabled, bad lines in page replaced by white lines
                2 = Packet loss concealment enabled, bad lines in page replaced by last good line
                3 = Reserved
    13          ECM Disable:
                0 = Allow ECM faxes in T.38 (default)
                1 = Prevent ECM faxes in T.38
    12:11       This parameter controls the UDPTL redundancy count for fax page data. The redundant
                message format is defined in section 9.4.1 of Recommendation T.38.
                Range: 0 (default) to 3
    10:8        This parameter controls the UDPTL redundancy count for T.30 messages. The redundant
                message format is defined in section 9.4.1 of Recommendation T.38.
                Range: 0 to 7, default 3.
    7:6         Reserved (set to zero)
    5:3         This parameter allows the host to limit the fax connection speed:
                0 = No speed limit (default)
                1 = 2400 bps limit
                2 = 4800 bps limit
                3 = 7200 bps limit
                4 = 9600 bps limit
                5 = 12000 bps limit
                6 = 14400 bps limit
    2           Reserved (set to zero)
    1           Error Recovery method
                0 = Redundancy (default)
                1 = FEC (Forward Error Correction)
    0           This parameter selects the TCF procedure to be in fax mode. For TCF procedure 1, the
                TCF data is not passed across the IP network. Each gateway independently generates or
                checks the TCF and only the result of the training is passed over the network. For TCF
                procedure 2, the TCF data is passed across the IP network in the same way as any other
                page data.
                0 = Procedure 2
                1 = Procedure 1 (default)   
    
    **/
    
    t38FaxOperValue |= pFaxOper->tcfPassThroughIpNetwork & 0x1;
    t38FaxOperValue |= (pFaxOper->errRecoverMethod & 0x1) << 1;
    /*平台定义的值与芯片定义一致,不用转换*/
    #if 0
    switch(pFaxOper->speed)
    {
        case 14400:
            tmpValue = 6;
            break;
        case 12000:
            tmpValue = 5;
            break;
        case 9600:
            tmpValue = 4;
            break;
        case 7200:
            tmpValue = 3;
            break;
        case 4800:
            tmpValue = 2;
            break;
        case 2400:
            tmpValue = 1;
            break;
        default:
            tmpValue = 0;
            break;
    }
    t38FaxOperValue |= /*pFaxOper->speed*/ (tmpValue & 0x7) << 3;
    #else
    t38FaxOperValue |= (pFaxOper->speed & 0x7) << 3;
    #endif
    t38FaxOperValue |= (pFaxOper->redundancyNumOfT30Msg & 0x7) << 8;
    t38FaxOperValue |= (pFaxOper->redundancyNumOfPageData & 0x3) << 11;
    if (pFaxOper->ECMFlag == VOIP_FAX_ECM_UNUSED)
    {
        t38FaxOperValue |= (0x01 & 0x01) << 13;
    }
    else
    {
        t38FaxOperValue |= (0x00 & 0x01) << 13;
    }
    /*t38FaxOperValue |= (pFaxOper->ECMFlag & 0x1) << 13;*/
    t38FaxOperValue |= (pFaxOper->lossPktConcealment & 0x3) << 14;
    
    t38FaxSignalLevel = pFaxOper->level & 0xF;

    /*配置T38 传真属性*/
    /*FIFO1 和FIFO2的参数应该从value解析出来*/
    semTake(M803xxQueueSem[portNo/8], WAIT_FOREVER);
    if (OK == M80320_checkOpenChanQueue(portNo, 0x04, FUN_FAXOPT))
    {
        InCmd = m_port[portNo].InCmd;
        gTmpT38FaxArg1 = t38FaxOperValue; 
        m_port[portNo].tx_cmd_fifo[InCmd] =  t38FaxOperValue;  /*only for test*/
        if( ++InCmd >= MAX_LEN_OF_CMD_FIFO)  
            InCmd = 0;
        
        /*缺省配置*/
        m_port[portNo].tx_cmd_fifo[InCmd] = gTmpT38FaxArg2  /*0x0062*/;
        if( ++InCmd >= MAX_LEN_OF_CMD_FIFO)  
            InCmd = 0;
        m_port[portNo].InCmd = InCmd;
    
        RemainedTxCmdNum[portNo] += 2;

        result = SendMsgToOpenChannelQueue(CMD_CMDDAT | ((m_port[portNo].Channel)%PORTS_OF_CHIP), 0x0004, 0x0200, FUN_FAXOPT, portNo);
    }
    semGive(M803xxQueueSem[portNo/8]);

    /*配置T38 FAX的信号强度*/
    /*This function code is used to set the transmit level in T.38 fax relay mode. The level
    parameter is passed in the first word of the FIFO. The level is expressed in -1dBm
    steps, within the range 0 – 15. The default value is 10 (0x0A), which corresponds to a
    transmit level of –10dBm.*/

    if (t38FaxSignalLevel == 0)
        t38FaxSignalLevel = 10;
    
    /*FIFO1 的参数应该从value解析出来*/
    semTake(M803xxQueueSem[portNo/8], WAIT_FOREVER);
    if (OK == M80320_checkOpenChanQueue(portNo, 0x02, FUN_FAXLVL))
    {
        InCmd = m_port[portNo].InCmd;
        m_port[portNo].tx_cmd_fifo[InCmd] = t38FaxSignalLevel /*t38FaxOperValue*/;  /*only for test*/
        if( ++InCmd >= MAX_LEN_OF_CMD_FIFO)  
            InCmd = 0;
        m_port[portNo].InCmd = InCmd;
    
        RemainedTxCmdNum[portNo] += 1;

        result = SendMsgToOpenChannelQueue(CMD_CMDDAT | ((m_port[portNo].Channel)%PORTS_OF_CHIP), 0x0002, 0x0200, FUN_FAXLVL, portNo);
    }
    semGive(M803xxQueueSem[portNo/8]);
    return(result);
}
/*-----------------------------
* constructIpUdpHeader - 构造 IP + UDP header
*
* Description:
* 
* Argument: 
*          portNo   -- No. Of The M803xx Port                     
* 
* Return:
*    void
*
* Modified history
*------------------------------
* 2006-3-23 20:13 ZhengaQishan Created.
*
**/
/*--------------UDPTL/IP包的结构,added by fengya-----------------------*/
/*              --------------------------------------------            */
/*              |  UPTL包头 | UDPTL有效负荷=IFP包+冗余/FEC |            */
/*              --------------------------------------------            */
/*              |                                          |            */
/*                |                                      |              */
/*                  |                                  |                */
/*                    |                              |                  */
/*                      |                          |                    */
/*                        |                      |                      */
/*                -------------------------------                       */ 
/*                |UDP包头|     UDP有效负荷     |                       */
/*                -------------------------------                       */
/*                |                             |                       */
/*              |                              |                        */
/*       --------------------------------------                         */
/*       |IP包头|      IP有效负荷              |                        */
/*       --------------------------------------                         */ 
/*                      |  |                                            */
/*                      |  |                                            */
/*       ---------------------------------------------------            */
/*       | IP包头 | UDP包头 | UDPTL包头 |   IFP包+冗余/FEC |            */ 
/*       ---------------------------------------------------            */
/*----------------------------------------------------------------------*/
                          
void constructIpUdpHeader(UINT8 portNo, int workMode)
{
    int loopCnt;
    UINT32 tmpValue;
    UINT8 *pIpUdpHeader = (UINT8 *)NULL;
    UINT32 TOS;   /*type of service*/
    ipaddr_t Ipaddr[2];
    UINT16   UdpPort[2];
    
    pIpUdpHeader = (UINT8 *)(gpT38FaxParameter[portNo]->t38FaxArg.ipUdpHeader);
    
    
    if (Fax == workMode)
    {
        for(loopCnt = 0; loopCnt < MAX_IP_ADDR_LEN; loopCnt++)
        {
            Ipaddr[0].addr[loopCnt] = gpT38FaxParameter[portNo]->localRtpAddress.ipAddr.addr[loopCnt];
            Ipaddr[1].addr[loopCnt] = gpT38FaxParameter[portNo]->remoteRtpAddress.ipAddr.addr[loopCnt];
        }
        UdpPort[0] = gpT38FaxParameter[portNo]->localRtpAddress.port;
        UdpPort[1] = gpT38FaxParameter[portNo]->remoteRtpAddress.port;
        TOS        = (UINT32)(gpT38FaxParameter[portNo]->Tos);
        pIpUdpHeader = gpT38FaxParameter[portNo]->t38FaxArg.ipUdpHeader;
    }
    else
    {
        for(loopCnt = 0; loopCnt < MAX_IP_ADDR_LEN; loopCnt++)
        {
            Ipaddr[0].addr[loopCnt] = Parameter[portNo].localRtpAddress.ipAddr.addr[loopCnt];
            Ipaddr[1].addr[loopCnt] = Parameter[portNo].remoteRtpAddress.ipAddr.addr[loopCnt];
        }
        UdpPort[0] = Parameter[portNo].localRtpAddress.port;
        UdpPort[1] = Parameter[portNo].remoteRtpAddress.port;
        TOS        = (UINT32)(Parameter[portNo].Tos);
        pIpUdpHeader = Parameter[portNo].t38FaxArg.ipUdpHeader;
    }

    voip_driver_check_qos_dscp(&TOS);
    
    if ((UINT8 *)NULL == pIpUdpHeader)
        taskSuspend(0);

    tmpValue = (0x45000000 | (((TOS & 0x3F) << 18) & 0xfc0000));
    SU32_TO_NET((UINT32 *)pIpUdpHeader, tmpValue);
    pIpUdpHeader += 4;

    tmpValue = (0x00000000);
    SU32_TO_NET((UINT32 *)pIpUdpHeader, tmpValue);
    pIpUdpHeader += 4;

    tmpValue = (0x7e110000);
    SU32_TO_NET((UINT32 *)pIpUdpHeader, tmpValue);
    pIpUdpHeader += 4;

    tmpValue = ((UINT32)((((UINT32)(Ipaddr[0].addr[0]))<<24)&0xff000000)
                    +(((Ipaddr[0].addr[1])<<16)&0x00ff0000)
                    +(((Ipaddr[0].addr[2])<<8)&0x0000ff00)
                    +((Ipaddr[0].addr[3])&0x000000ff));
    SU32_TO_NET((UINT32 *)pIpUdpHeader, tmpValue);
    pIpUdpHeader += 4;

    tmpValue = ((UINT32)((((UINT32)(Ipaddr[1].addr[0]))<<24)&0xff000000)
                    +(((Ipaddr[1].addr[1])<<16)&0x00ff0000)
                    +(((Ipaddr[1].addr[2])<<8)&0x0000ff00)+
                    ((Ipaddr[1].addr[3])&0x000000ff));
    SU32_TO_NET((UINT32 *)pIpUdpHeader, tmpValue);
    pIpUdpHeader += 4;

    tmpValue = (((((UINT32)UdpPort[0])<<16)&0xffff0000)+(((UINT32)UdpPort[1])&0x0000ffff));
    SU32_TO_NET((UINT32 *)pIpUdpHeader, tmpValue);
    pIpUdpHeader += 4;

    tmpValue = (0x00000000);
    SU32_TO_NET((UINT32 *)pIpUdpHeader, tmpValue);
}

/*-----------------------------
* SendFaxPktDebug - T.38 FAX发包的debug信息
*
* Description:
* 
* Argument: 
*                                             
*                portNo   -- No. Of The M803xx Port                     
*                Len      -- Length Of The Data                         
*                
* Return:
*    void
*
* Modified history
*------------------------------
*
**/
void SendFaxPktDebug(UINT32 *buf, UINT8 PortNo, UINT16 Len)
{
    UINT8 Rtp_Head[100], i=0;
    UINT32 gPort=0;
    int dbgClass = 0;

    memset(Rtp_Head,0,sizeof(Rtp_Head));
    gPort = (((UINT32)((CON_TO_DP[m_port[PortNo].Channel].chan)+1)<<16))+((CON_TO_DP[m_port[PortNo].Channel].chip+1)<<24);  /* 全局端口号 */

    if(m_port[PortNo].CallType == LFXS_CALLTYPE_IN)
    {
        dbgClass = /*faxrelaypacket|*/ faxrelaypacketcalled;
    }
    else if(m_port[PortNo].CallType == LFXS_CALLTYPE_OUT)
    {
        dbgClass = /*faxrelaypacket |*/ faxrelaypacketcalling;
    }

    faxDebug(dbgClass, gPort, " Receive packet %d bytes!", Len);
    if (Len>100)
    {
        Len = 100;
    }
    for(i=0; i<Len; i++)
    {
        Rtp_Head[i] = (UINT8)((((UINT8 *)buf)[i]));
    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -