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

📄 zl5011xpktpassthru.c

📁 Zalink50114----TDMoIP芯片驱动源码
💻 C
📖 第 1 页 / 共 3 页
字号:
               packetTxSetHeader.queueNum = par->upLinkQueueNum;
            }
            else
            {  /* Second flow transmits on downlink port */
               packetTxSetHeader.portNum = par->downLinkPort;
               packetTxSetHeader.queueNum = par->downLinkQueueNum;
            }
            status = zl5011xPacketTxSetHeader(zl5011xParams, &packetTxSetHeader);
         }
      }

      /* Update all the packet-to-packet contexts */
      {
         zl5011xContextS        contextStruct;

         if (status == ZL5011X_OK)
         {
            status = zl5011xLanLanContextUpdateStructInit(zl5011xParams,
                                                &contextStruct);
         }
         /* Set parameters */
         if (status == ZL5011X_OK)
         {
            contextStruct.osExclusionEnable = ZL5011X_FALSE;  /* OS exclusion, if enabled, has already been done */
            contextStruct.context = par->context[i];
            status = zl5011xLanLanContextUpdate(zl5011xParams, &contextStruct);
         }
      }
   }

   if (gotDevice == ZL5011X_TRUE)
   {
      if (status == ZL5011X_OK)
      {
         status = zl5011xReleaseDevice(zl5011xParams);
      }
      else
      {
         /* already have an error code, so don't overwrite it */
         (void)zl5011xReleaseDevice(zl5011xParams);
      }
   }

   return status;
}


/*******************************************************************************

 Function:
    zl5011xDeletePktToPktPassthruStructInit

 Description:
   Initialises structure used by functions zl5011xDeletePktToPktPassthru

 Inputs:
   zl5011xParams   Pointer to the structure for this device instance
   par            Pointer to the structure for configuration items.
                  See main function

 Returns:
   zlStatusE

 Remarks:

******************************************************************************/

zlStatusE zl5011xDeletePktToPktPassthruStructInit(zl5011xParamsS *zl5011xParams,
            zl5011xDeletePktToPktPassthruS *par)
{
   zlStatusE status = ZL5011X_OK;
   Sint32T i;

   ZL5011X_TRACE(ZL5011X_PACKET_FN_ID,"zl5011xDeletePktToPktPassthruStructInit:",0, 0, 0, 0, 0, 0);

   /* do some parameter checking */
   status = ZL5011X_CHECK_POINTERS(zl5011xParams, par);

   if (status == ZL5011X_OK)
   {
      for (i = 0; i < ZL5011X_NUM_PKT_PKT_FLOWS; i++)
      {
         par->context[i] = (Uint32T)ZL5011X_INVALID_CONTEXT;   /* Contexts must be specifed by application */
      }
      par->osExclusionEnable = ZL5011X_TRUE;   /* Default to using OS exclusion when accessing the
                                                device from this function */
   }

   return status;
}

/*******************************************************************************

 Function:
    zl5011xDeletePktToPktPassthru

 Description:
   Deletes a previously established Packet-to-Packet flow.

 Structure inputs:
   context              The context numbers to delete. This will be the numbers that
                        were returned from the zl5011xCreatePktToPktPassthru function
                        in the "context" element of the parameter structure.
                        Default = none. Must be set by application
   osExclusionEnable    ZL5011X_TRUE to enable OS exclusion
                        Default = ZL5011X_TRUE

 Structure outputs:
   none

 Returns:
    status            Any valid error code

 Remarks:

*******************************************************************************/

zlStatusE zl5011xDeletePktToPktPassthru(zl5011xParamsS *zl5011xParams, zl5011xDeletePktToPktPassthruS *par)
{
   zlStatusE status = ZL5011X_OK;
   zl5011xBooleanE gotDevice;
   /* The hardware supports two classifier matches for each context. Packet-to-Packet contexts only use the first one */
   Uint32T currentHeader = 0;
   Uint16T classifyNum;  /* The classifier number assigned to this context */
   Uint8T protocolMatch; /* The protocol match for this classifier number */
   Sint32T i;

   /* do some parameter checking */
   status = ZL5011X_CHECK_POINTERS(zl5011xParams, par);

   /* Obtain exclusive access to the device if required */
   if ((status == ZL5011X_OK) && (par->osExclusionEnable == ZL5011X_TRUE))
   {
     /* get access to the device */
     status = zl5011xGetDevice(zl5011xParams, ZL5011X_GET_DEVICE_TIMEOUT_MODE);

     if (status == ZL5011X_OK)
     {
         gotDevice = ZL5011X_TRUE;
     }
   }

   for (i = 0; (i < ZL5011X_NUM_PKT_PKT_FLOWS) && (status == ZL5011X_OK); i++)
   {
      /* Is this a Packet-to-Packet context? */
      if (status == ZL5011X_OK)
      {
         if (zl5011xParams->packetIf.lanLanContext[par->context[i]] == ZL5011X_FALSE)
         {  /* Not a packet-to-packet context */
            status = ZL5011X_CONTEXT_NOT_IN_USE;
         }
      }

      if (status == ZL5011X_OK)
      {
         /* Find the classifier number assigned to this context */
         classifyNum = zl5011xParams->packetIf.packetRx.contextRxPacketMatch[par->context[i]].pkcClassifyMatchNum[currentHeader];
         /* Find the protocol match used by this classifier number */
         protocolMatch = zl5011xParams->packetIf.packetRx.pkcClassify[classifyNum].classifyMatch.protocolMatchNum;
      }

      {
         /* Delete the packet to packet context */
         zl5011xContextDeleteS contextDelete;

         if (status == ZL5011X_OK)
         {
            status = zl5011xContextDeleteStructInit(zl5011xParams, &contextDelete);
         }
         if (status == ZL5011X_OK)
         {
            contextDelete.context = par->context[i];
            contextDelete.osExclusionEnable = ZL5011X_FALSE;
            status = zl5011xLanLanContextDelete(zl5011xParams, &contextDelete);
         }
      }

      /* Delete the packet to packet protocol match. */
      /* Since the same protocol match is used for all the passthru flows it will only
         actually be deleted when the final passthru context is deleted. */
      {
         zl5011xPacketRxDeleteProtocolMatchNumS packetRxDeleteProtocolMatchNum;

         if (status == ZL5011X_OK)
         {
            status = zl5011xPacketRxDeleteProtocolMatchNumStructInit(zl5011xParams, &packetRxDeleteProtocolMatchNum);
         }
         if (status == ZL5011X_OK)
         {
            packetRxDeleteProtocolMatchNum.protocolMatchNum = protocolMatch;
            packetRxDeleteProtocolMatchNum.osExclusionEnable = ZL5011X_FALSE;   /* Exclusion already performed */
            status = zl5011xPacketRxDeleteProtocolMatchNum(zl5011xParams, &packetRxDeleteProtocolMatchNum);
         }
      }
   }

   /* Release the device */
   if (gotDevice == ZL5011X_TRUE)
   {
      if (status == ZL5011X_OK)
      {
         status = zl5011xReleaseDevice(zl5011xParams);
      }
      else
      {
         /* already have an error code, so don't overwrite it */
         (void)zl5011xReleaseDevice(zl5011xParams);
      }
   }

   return status;
}

/******************************************************************************

 Function:
    zl5011xGetClassifierNumFromPriorityOrder

 Description:
   Returns the classifier number that is at the priority position specified.

   The classifier matches are compared in sets of 17 at a time. The set
   contains a number of matches which are not in consecutive number order.
   The first compare processes match numbers 0,16,32...256 and the second
   compare handles 1,17,33, etc.
   Within each compare set the classifier priority is in ascending numerical
   order.
   The compare operation for each set takes one clock cycle. The first set
   and first match to be found is the one that will be used.

   This function converts an absolute priority number into the actual
   classification match number at that priority position.

 Inputs:
   matchPriority   The priority number from which to determine the match
                   Range = 0(highest)-271(lowest priority),

 Returns:
   classifier number at this priority position.
                        Range = 0-271

 Remarks:
   The classifier number occupying priority position n is given by
   16 x (n mod 17) + int(n/17)

******************************************************************************/

Uint32T zl5011xGetClassifierNumFromPriorityOrder(Uint32T matchPriority)
{
   const Uint32T classifierGroupIncrement = 16; /* "Consecutive" classifier numbers
                        in each group increment by 16 */
   const Uint32T comparesInEachGroup = 17;

   return (classifierGroupIncrement * (matchPriority % comparesInEachGroup)) +
                  (matchPriority / comparesInEachGroup);
}

⌨️ 快捷键说明

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