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

📄 zl5011xlan.c

📁 Zalink50114----TDMoIP芯片驱动源码
💻 C
📖 第 1 页 / 共 5 页
字号:

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

 Returns:
   zlStatusE

 Remarks:
    None

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

zlStatusE zl5011xLanRxSetProtocolMatchStructInit(zl5011xParamsS *zl5011xParams,
      zl5011xLanRxSetProtocolMatchS *par)
{
   zlStatusE status = ZL5011X_OK;
   Uint8T loop;

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

   /* main function code starts */

   if (status == ZL5011X_OK)
   {
      ZL5011X_TRACE(ZL5011X_LAN_FN_ID,
            "zl5011xLanRxSetProtocolMatchStructInit:",
            0, 0, 0, 0, 0, 0);

      /* put the matchNum to an invalid value. If it is left at this, the
         API will automatically allocate a match */
      par->matchNum = (Uint32T)ZL5011X_INVALID;

      /* reset all of the entries in the match part of the structure */
      for (loop = 0; loop < ZL5011X_PKC_PROTOCOL_NUM_MATCH_FIELDS; loop++)
      {
         par->match.protocolMatchBytes[loop] = 0;
         par->match.protocolMaskBytes[loop] = 0xff;   /* Match no bits */
      }

      /* reset all of the entries in the output part of the structure */
      for (loop = 0; loop < ZL5011X_PKC_CLASSIFY_NUM_MATCH_FIELDS; loop++)
      {
         /* default the classify bytes to the first byte in the header */
         par->output.extractClassifyBytes[loop] = 0;
      }

      for (loop = 0; loop < ZL5011X_PKC_CLASSIFY_NUM_CHECK_FIELDS; loop++)
      {
         /* default the check bytes to the first byte in the header */
         par->output.extractCheckBytes[loop] = 0;

         /* mask off all of the bits, so that none are used in the
            check */
         par->output.checkMask[loop] = 0xff;
      }

      par->output.extractPwByte = 0x0;

      for (loop = 0; loop < ZL5011X_PKC_PROTOCOL_MAX_SEQ_BYTES; loop++)
      {
         /* default the sequence number to the first byte in the header */
         par->output.extractSequenceBytes[loop] = 0;
      }

      for (loop = 0; loop < ZL5011X_PKC_PROTOCOL_MAX_TIMESTAMP_BYTES; loop++)
      {
         /* default the timestamp to the first byte in the header */
         par->output.extractTimestampBytes[loop] = 0;
      }

      for (loop = 0; loop < ZL5011X_PKC_PROTOCOL_MAX_LENGTH_BYTES; loop++)
      {
         /* default the length field to the first byte in the header */
         par->output.extractLengthBytes[loop] = 0x0;
      }

      par->output.discardUdpCheckFails = ZL5011X_TRUE;
      par->output.protocolIpv4 = ZL5011X_TRUE;
      par->output.protocolVlan = ZL5011X_FALSE;
      par->output.protocolTwoByteSeq = ZL5011X_TRUE;
      par->output.timestampShift = 0;

      par->osExclusionEnable = ZL5011X_TRUE;
   }

   return status;
}

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

 Function:
   zl5011xLanRxSetProtocolMatch

 Description:
   Sets up a protocol match in the packet Rx. A protocol match controls which
   fields are extracted from the Rx packet to be used for classification.

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

 Structure inputs:
   matchNum       which protocol match to use - can be set to ZL5011X_INVALID
                  when any available match will be found
   match          structure to hold settings for the matching part of the
                  protocol match
   output         structure to hold which bytes to use for classification etc.
   osExclusionEnable ZL5011X_TRUE to enable OS exclusion

 Structure outputs:
   None

 Returns:
   zlStatusE

 Remarks:
   None

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

zlStatusE zl5011xLanRxSetProtocolMatch(zl5011xParamsS *zl5011xParams,
      zl5011xLanRxSetProtocolMatchS *par)
{
   zlStatusE status = ZL5011X_OK;
   zl5011xBooleanE assignedMatch = ZL5011X_FALSE;
   zl5011xBooleanE gotDevice = ZL5011X_FALSE;

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

   if (status == ZL5011X_OK)
   {
      status = ZL5011X_CHECK_RUNNING(zl5011xParams);
   }

   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;
      }
   }

   /* main function code starts */

   if (status == ZL5011X_OK)
   {
      ZL5011X_TRACE(ZL5011X_LAN_FN_ID,
            "zl5011xLanRxSetProtocolMatch:",
            0, 0, 0, 0, 0, 0);

      status = zl5011xPkcProtocolGetFreeEntry(zl5011xParams, &(par->matchNum));
   }

   /* if a match has been reserved then remember, so that it can be
      free'd up if things go wrong */
   if (status == ZL5011X_OK)
   {
      assignedMatch = ZL5011X_TRUE;
   }
   else
   {
      /* if the protocol match had already been allocated, then just
         continue, but disable the entry before re-programming it. */
      if (status == ZL5011X_PROTOCOL_MATCH_IN_USE)
      {
         status = zl5011xPkcProtocolDisableEntry(zl5011xParams, par->matchNum);
      }
   }

   /* setup the protocol match */
   if (status == ZL5011X_OK)
   {
      status = zl5011xPkcProtocolSetMatch(zl5011xParams,
            par->matchNum, &(par->match), &(par->output));
   }

   /* enable the protocol if it has been set up successfully */
   if (status == ZL5011X_OK)
   {
      status = zl5011xPkcProtocolEnableEntry(zl5011xParams, par->matchNum);
   }
   else
   {
      /* failed, so free up the match number if it was allocated by this
         function */
      if (assignedMatch == ZL5011X_TRUE)
      {
         /* ignore the return code, since we already have an error. Just
            recover as best as possible */
         (void)zl5011xPkcProtocolDeleteEntry(zl5011xParams, par->matchNum);
      }
   }

   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:
    zl5011xLanRxDeleteProtocolMatchStructInit

 Description:
   Initialises structure used by zl5011xLanRxDeleteProtocolMatch function.

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

 Returns:
   zlStatusE

 Remarks:
    None

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

zlStatusE zl5011xLanRxDeleteProtocolMatchStructInit(zl5011xParamsS *zl5011xParams,
      zl5011xLanRxDeleteProtocolMatchS *par)
{
   zlStatusE status = ZL5011X_OK;

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

   /* main function code starts */

   if (status == ZL5011X_OK)
   {
      ZL5011X_TRACE(ZL5011X_LAN_FN_ID,
            "zl5011xLanRxDeleteProtocolMatchStructInit:",
            0, 0, 0, 0, 0, 0);

      par->matchNum = (Uint32T)ZL5011X_INVALID;

      par->osExclusionEnable = ZL5011X_TRUE;
   }

   return status;
}

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

 Function:
   zl5011xLanRxDeleteProtocolMatch

 Description:
   Deletes a protocol match.

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

 Structure inputs:
   matchNum       protocol match to delete
   osExclusionEnable ZL5011X_TRUE to enable OS exclusion

 Structure outputs:
   None

 Returns:
   zlStatusE

 Remarks:
   None

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

zlStatusE zl5011xLanRxDeleteProtocolMatch(zl5011xParamsS *zl5011xParams,
      zl5011xLanRxDeleteProtocolMatchS *par)
{
   zlStatusE status = ZL5011X_OK;
   zl5011xBooleanE gotDevice = ZL5011X_FALSE;

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

   if (status == ZL5011X_OK)
   {
      status = ZL5011X_CHECK_RUNNING(zl5011xParams);
   }

   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;
      }
   }

   /* main function code starts */

   if (status == ZL5011X_OK)
   {
      ZL5011X_TRACE(ZL5011X_LAN_FN_ID,
            "zl5011xLanRxDeleteProtocolMatch: match %d",
            par->matchNum, 0, 0, 0, 0, 0);

      status = zl5011xPkcProtocolDeleteEntry(zl5011xParams, par->matchNum);
   }

   if (status == ZL5011X_OK)
   {
      /* update the protocol type in the device structure - useful for debugging */
      zl5011xParams->packetIf.packetRx.pkcProtocol[par->matchNum].protocolType = ZL5011X_INVALID_PROTOCOL;
   }

   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:
    zl5011xLanRxSetContextMatchStructInit

 Description:
   Initialises structure used by zl5011xLanRxSetContextMatch function.

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

 Returns:
   zlStatusE

 Remarks:
    None

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

zlStatusE zl5011xLanRxSetContextMatchStructInit(zl5011xParamsS *zl5011xParams,
      zl5011xLanRxSetContextMatchS *par)
{
   zlStatusE status = ZL5011X_OK;
   Uint8T loop;

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

   /* main function code starts */

   if (status == ZL5011X_OK)
   {
      ZL5011X_TRACE(ZL5011X_LAN_FN_ID,
            "zl5011xLanRxSetContextMatchStructInit:",
            0, 0, 0, 0, 0, 0);

      par->context = (Uint32T)ZL5011X_INVALID_CONTEXT;

      /* put the matchNum to an invalid value. If it is left at this, the
         API will automatically allocate a match */
      par->matchNum = (Uint32T)ZL5011X_INVALID;

      /* reset all of the entries in the match part of the structure */
      par->match.protocolMatchNum = (Uint8T)ZL5011X_INVALID;

⌨️ 快捷键说明

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