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

📄 le1veconfig.c

📁 Zalink50114----TDMoIP芯片驱动源码
💻 C
📖 第 1 页 / 共 5 页
字号:
	  layer2and3Header->header.ethernetSrcAddressFromMac = par->ethernetSrcAddressFromMac;
	}

	/* set the Lan port and queue for this packet header */
	if (status == ZL5011X_OK)
	{
	  status = zl5011xPkqSetMpidConnection(zl5011xParams, par->context,
	        par->portNum, par->queueNum);
	}
	/* set the header */
	if (status == ZL5011X_OK)
	{
	  status = zl5011xPtxSetHeader(zl5011xParams, par->context, &(layer2and3Header->header));

	if (status == ZL5011X_OK)
	  {
	     /* the header for the loopback Tx has now been set, so mark the
	        context as in use to prevent it from being changed */
	     zl5011xParams->wanIf.plaCurrent.context[par->context].state = ZL5011X_STATE_INIT;
	  }
	}
 
	/* free up the memory allocated for the headers */
	if (layer2and3Header != NULL)
	{
	  free(layer2and3Header);
	}
    #endif
      /* Now set up the transmit side.
         The packet is to be unchanged apart from changing the source MAC address. The control
         for this is provided by the zl5011xLanTxSetLayer2and3Header function so we tell this to
         add a zero length header. */
      {
         zl5011xLanTxSetLayer2and3HeaderS layer2and3Header;

         /* Call the lower level API structure initialisation functions */
         status = zl5011xLanTxSetLayer2and3HeaderStructInit(zl5011xParams, &layer2and3Header);

         layer2and3Header.context = par->context; /* The context we are setting up */
         layer2and3Header.header.txLowLength = 0;
         layer2and3Header.header.ethernetSrcAddressFromMac = par->ethernetSrcAddressFromMac;

         /* The following header parameters are not relevant since we are adding no header, so
            leave these at their defaults:
               layer2and3Header.header.layer2LengthEnable = ZL5011X_FALSE;
               layer2and3Header.header.layer3LengthEnable = ZL5011X_FALSE;
               layer2and3Header.header.layer3ChecksumEnable = ZL5011X_FALSE; */

         /* Specify the egress port for data on this context */
         layer2and3Header.portNum = par->portNum;
         layer2and3Header.queueNum = par->queueNum;

         /* With the fully populated structure, call the API function to setup this
            transmit */
         status = zl5011xLanTxSetLayer2and3Header(zl5011xParams, &layer2and3Header);
      }  
   	return(status);
}
/******************************
*drv_Le1veDeleteARP() -  to delete protocolmatch and context match
*Description:
*                delete ARP match
*Argument:
*               
*                 
*
*Return:
* OK or ERROR
*-----------------------------
*modification history
*-----------------------------
* 
*2005.7.11 shf created
******************************/
zlStatusE drv_le1veDeleteARP(int slot)
{
	zlStatusE status = ZL5011X_OK;
	/*zl5011xLanRxDeleteContextMatchS par;
	zl5011xLanRxDeleteProtocolMatchS arpDeleltePar;*/
	zl5011xParamsS *pZl5011xParams;
       pZl5011xParams = le1ve_Zl5011xParams[slot - 1];
	status=ZL5011X_CHECK_SLOTNUM(slot, pZl5011xParams);
    #if 0
       /*delete context match*/
	if(status == ZL5011X_OK)
	{			
	       status=zl5011xLanRxDeleteContextMatchStructInit(pZl5011xParams, &par);
	}
	if(status == ZL5011X_OK)
	{
		par.context = LE1VE_ARP_IN_CONTEXT_NUM;
		status =drv_Le1vePacketForwardDeleteContextMatch(pZl5011xParams, &par);
	}
	if(status == ZL5011X_OK)
	{
		par.context = LE1VE_ARP_OUT_CONTEXT_NUM;

		status =drv_Le1vePacketForwardDeleteContextMatch(pZl5011xParams, &par);
	}
	/*delete protocol match*/
	if(status == ZL5011X_OK)
	{
		status= zl5011xLanRxDeleteProtocolMatchStructInit(pZl5011xParams, &arpDeleltePar);
	}
	if(status == ZL5011X_OK)
	{
		arpDeleltePar.matchNum =ZL5011X_PKC_NUM_PROTOCOL_ENTRIES - 1 ;
	       status= zl5011xLanRxDeleteProtocolMatch(pZl5011xParams, &arpDeleltePar);
	}
    #endif
   /**************************************************************************/
   /* Closedown flows                                                        */
   /**************************************************************************/
   {
      zl5011xContextDeleteS contextDeleteStruct;

      /* Closedown contexts from flows 1, 2 and 3 */

      /* Delete the context */
      status = zl5011xContextDeleteStructInit(pZl5011xParams, &contextDeleteStruct);

   
         /* Set the context to be deleted and delete it */
      contextDeleteStruct.context = LE1VE_ARP_IN_CONTEXT_NUM;
      status = zl5011xLanLanContextDelete(pZl5011xParams, &contextDeleteStruct);

      contextDeleteStruct.context = LE1VE_ARP_OUT_CONTEXT_NUM;
      status = zl5011xLanLanContextDelete(pZl5011xParams, &contextDeleteStruct);
   }

   /**************************************************************************/
   /* Delete protocol matches used                                           */
   /**************************************************************************/
   {
      /* Remove unused protocols from classification engine               */
      /* This example used three protocol matches */
    
         zl5011xLanRxDeleteProtocolMatchS structLanRxDeleteProtocolMatch;

         status = zl5011xLanRxDeleteProtocolMatchStructInit(pZl5011xParams, &structLanRxDeleteProtocolMatch);
        

         structLanRxDeleteProtocolMatch.matchNum = ZL5011X_PKC_NUM_PROTOCOL_ENTRIES - 1;

         status = zl5011xLanRxDeleteProtocolMatch(pZl5011xParams, &structLanRxDeleteProtocolMatch);
        
     
   }

   return status;
}

zlStatusE drv_le1veDeleteICMP(int slot)
{
       zlStatusE status = ZL5011X_OK;
	zl5011xParamsS *pZl5011xParams;
	/*zl5011xLanRxDeleteContextMatchS par;
	zl5011xLanRxDeleteProtocolMatchS icmpDeleltePar;*/
       pZl5011xParams = le1ve_Zl5011xParams[slot - 1];
	status=ZL5011X_CHECK_SLOTNUM(slot, pZl5011xParams);
    #if 0
       /*delete context match*/
	if(status == ZL5011X_OK)
	{			
	       status=zl5011xLanRxDeleteContextMatchStructInit(pZl5011xParams, &par);
	}
	if(status == ZL5011X_OK)
	{
		par.context = LE1VE_ICMP_IN_CONTEXT_NUM;
		status =drv_Le1vePacketForwardDeleteContextMatch(pZl5011xParams, &par);
	}
	if(status == ZL5011X_OK)
	{
		par.context = LE1VE_ICMP_OUT_CONTEXT_NUM;

		status =drv_Le1vePacketForwardDeleteContextMatch(pZl5011xParams, &par);
	}
	/*delete protocol match*/
	if(status == ZL5011X_OK)
	{
		status= zl5011xLanRxDeleteProtocolMatchStructInit(pZl5011xParams, &icmpDeleltePar);
	}
	if(status == ZL5011X_OK)
	{
		icmpDeleltePar.matchNum =ZL5011X_PKC_NUM_PROTOCOL_ENTRIES - 2 ;
	       status= zl5011xLanRxDeleteProtocolMatch(pZl5011xParams, &icmpDeleltePar);
	}
    #endif

   /**************************************************************************/
   /* Closedown flows                                                        */
   /**************************************************************************/
   {
      zl5011xContextDeleteS contextDeleteStruct;

      /* Closedown contexts from flows 1, 2 and 3 */

      /* Delete the context */
      status = zl5011xContextDeleteStructInit(pZl5011xParams, &contextDeleteStruct);

   
         /* Set the context to be deleted and delete it */
      contextDeleteStruct.context = LE1VE_ICMP_IN_CONTEXT_NUM;
      status = zl5011xLanLanContextDelete(pZl5011xParams, &contextDeleteStruct);

      contextDeleteStruct.context = LE1VE_ICMP_OUT_CONTEXT_NUM;
      status = zl5011xLanLanContextDelete(pZl5011xParams, &contextDeleteStruct);
   }

   /**************************************************************************/
   /* Delete protocol matches used                                           */
   /**************************************************************************/
   {
      /* Remove unused protocols from classification engine               */
      /* This example used three protocol matches */
    
         zl5011xLanRxDeleteProtocolMatchS structLanRxDeleteProtocolMatch;

         status = zl5011xLanRxDeleteProtocolMatchStructInit(pZl5011xParams, &structLanRxDeleteProtocolMatch);
        

         structLanRxDeleteProtocolMatch.matchNum = ZL5011X_PKC_NUM_PROTOCOL_ENTRIES - 2;

         status = zl5011xLanRxDeleteProtocolMatch(pZl5011xParams, &structLanRxDeleteProtocolMatch);
        
     
   }
    
      return status;
}
/******************************
*drv_Le1vePacketForwardRxSet -  to set protocolmatch and context match
*Description:
*                对应ARP和ICMP设置协议匹配和上下文匹配
*Argument:
*               IN: par->direction, par->context, par->protocolType, par->sourceMac
*                    par->destinationIP
*
*Return:
* OK or ERROR
*-----------------------------
*modification history
*-----------------------------
* 
*2005.7.5 shf created
******************************/
zlStatusE drv_Le1vePacketForwardRxSet(zl5011xParamsS *zl5011xParams,
      Le1vePacketForwardConfigs *par)
{
	 zlStatusE status = ZL5011X_OK;
	UINT i;
	zl5011xLanRxSetContextMatchS contextMatch;
	status = ZL5011X_CHECK_POINTERS(zl5011xParams, par);
	if (status == ZL5011X_OK)
	{
	  status = ZL5011X_CHECK_RUNNING(zl5011xParams);
	}
	if(status == ZL5011X_OK)
	{
		/* initialise the context match settings */
   		status = zl5011xLanRxSetContextMatchStructInit(zl5011xParams, &contextMatch);
	}
	if(status == ZL5011X_OK)
    {
		if(par->protocolType == LE1VE_FORWORD_ARP)
		{
			/*设值outpout 数据,用于TM message*/
			contextMatch.output.classifyHeaderOffset = 0;
			contextMatch.output.classifyFlow = ZL5011X_FLOW_PKT_PKT;
			contextMatch.output.classifyLengthFromPacket = ZL5011X_TRUE;
			contextMatch.match.protocolMatchNum = par->protocolMatchNum;
			/*设置匹配数据.出方向匹配MAC
			入方向匹配目的IP. 两个参数必须协议或支撑提供
			*/
			if(par->forwardDirction == DIRECTION_OUT)
			{
                contextMatch.context = LE1VE_ARP_OUT_CONTEXT_NUM;
				contextMatch.output.classifyMpid = LE1VE_ARP_OUT_CONTEXT_NUM;	
				for(i=0 ; i<ZL5011X_IP_SIZE; i++)
				{
					contextMatch.match.classifyMatchBytes[i] = *(par->ipAddr+i);
					contextMatch.match.classifyMaskBytes[i] = ZL5011X_MASK_IN;
				}
			}
			else 
			{
                contextMatch.context = LE1VE_ARP_IN_CONTEXT_NUM;
				contextMatch.output.classifyMpid = LE1VE_ARP_IN_CONTEXT_NUM;
				for(i=0; i<ZL5011X_IP_SIZE; i++)
				{
					contextMatch.match.classifyMatchBytes[ZL5011X_IP_SIZE+i]= *(par->ipAddr+i);
					contextMatch.match.classifyMaskBytes[ZL5011X_IP_SIZE+i]= ZL5011X_MASK_IN;
				}
			}
		}
        else if(par->protocolType == LE1VE_FORWORD_ICMP)
        {
              	/*设值outpout 数据,用于TM message*/
			contextMatch.output.classifyHeaderOffset = 0;
			contextMatch.output.classifyFlow = ZL5011X_FLOW_PKT_PKT;
			contextMatch.output.classifyLengthFromPacket = ZL5011X_TRUE;
			contextMatch.match.protocolMatchNum = par->protocolMatchNum;	
			/*设置匹配数据.出方向匹配MAC
			入方向匹配目的IP. 两个参数必须协议或支撑提供
			*/
			if(par->forwardDirction == DIRECTION_OUT)
			{
                contextMatch.context = LE1VE_ICMP_OUT_CONTEXT_NUM;
				contextMatch.output.classifyMpid = LE1VE_ICMP_OUT_CONTEXT_NUM;	
				for(i=0 ; i<ZL5011X_IP_SIZE; i++)
				{
					contextMatch.match.classifyMatchBytes[i] = *(par->ipAddr+i);
					contextMatch.match.classifyMaskBytes[i] = ZL5011X_MASK_IN;
				}
			}
			else 
			{
                contextMatch.context = LE1VE_ICMP_IN_CONTEXT_NUM;
				contextMatch.output.classifyMpid = LE1VE_ICMP_IN_CONTEXT_NUM;
				for(i=0; i<ZL5011X_IP_SIZE; i++)
				{
					contextMatch.match.classifyMatchBytes[ZL5011X_IP_SIZE+i]= *(par->ipAddr+i);
					contextMatch.match.classifyMaskBytes[ZL5011X_IP_SIZE+i]= ZL5011X_MASK_IN;
				}
			}

        }  
        contextMatch.output.classifyFlow = (zl5011xFlowTypeE)ZL5011X_INVALID;   
        contextMatch.output.classifyMpid = (Uint32T)ZL5011X_INVALID; 
		status = zl5011xLanRxSetContextMatch(zl5011xParams, &contextMatch);
	}
	return status;
}
/*****************************
*drv_Le1vePacketForwardSetProtocol - set protocol match
*Description:
*                set the ARP or ICMP match to classify the packet stream
*
*Argument:
*               IN: par->protocolType,
*		   OUT: par->protocolMatchNum,
*
*Return:
*	OK or ERROR
*------------------------------
*modification history
*------------------------------
*2005.7.5 shf created
*
******************************/
zlStatusE drv_Le1vePacketForwardSetProtocol(zl5011xParamsS *zl5011xParams,
      Le1vePacketForwardConfigs *par)
{
	zlStatusE status=ZL5011X_OK;
	UINT i;
	zl5011xLanRxSetProtocolMatchS lanRxSetProtocolMatch;
	/* do some parameter checking */
	status = ZL5011X_CHECK_POINTERS(zl5011xParams, par);
	if (status == ZL5011X_OK)
	{
	  status = ZL5011X_CHECK_RUNNING(zl5011xParams);
	}
	if(status == ZL5011X_OK)
	{
		/*创建协议匹配结构*/
		status=zl5011xLanRxSetProtocolMatchStructInit(zl5011xParams, &lanRxSetProtocolMatch);
	}
	if (status == ZL5011X_OK)
	{
		if(par->protocolType == LE1VE_FORWORD_ARP)
		{
			lanRxSetProtocolMatch.matchNum = ZL5011X_PKC_NUM_PROTOCOL_ENTRIES - 1;
			/*ARP协议位为0x0806*/
			lanRxSetProtocolMatch.match.protocolMatchBytes[PROTOCOL_ARP_POS]= 0x08;
			lanRxSetProtocolMatch.match.protocolMatchBytes[PROTOCOL_ARP_POS+1]= 0x06;
			lanRxSetProtocolMatch.match.protocolMaskBytes[PROTOCOL_ARP_POS] = 0x00;
			lanRxSetProtocolMatch.match.protocolMaskBytes[PROTOCOL_ARP_POS+1] = 0x00;

⌨️ 快捷键说明

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