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

📄 zl5011xlan.c

📁 Zalink50114----TDMoIP芯片驱动源码
💻 C
📖 第 1 页 / 共 5 页
字号:
         filters[macIndex].match.macAddress[2] = 0x00;
         filters[macIndex].match.macAddress[1] = 0x00;
         filters[macIndex].match.macAddress[0] = 0x00;
         filters[macIndex].match.macAddressNumMaskBits = 8;   /* Mask off 8 bits from the
              right most part of the MAC address. */

         macIndex++;
      }
   }

   if (status == ZL5011X_OK)
   {
      /* Initialise the structures for the ethertype filters */
      if (par->filterArpEnable == ZL5011X_TRUE)
      {
         filters[typeIndex].match.ethertypeFilterEnable = ZL5011X_TRUE;

         /* for ARP packets, the ethertype is 0x0806 */
         filters[typeIndex].match.ethertype = 0x0806;

         typeIndex++;
      }

      if (par->filterRarpEnable == ZL5011X_TRUE)
      {
         filters[typeIndex].match.ethertypeFilterEnable = ZL5011X_TRUE;

         /* for RARP packets, the ethertype is 0x8035 */
         filters[typeIndex].match.ethertype = 0x8035;

         typeIndex++;
      }
   }

   /* set the filters up */
   for (loop = 0; (loop < macIndex) || (loop < typeIndex); loop++)
   {
      if (status != ZL5011X_OK)
      {
         break;
      }

      status = zl5011xLanRxSetFilterMatch(zl5011xParams, filters + loop);
   }

   /* if failed trying to set the filters (that is after struct init), then
      clean up any filters that were assigned */
   if ((status != ZL5011X_OK) && (failedInit == ZL5011X_FALSE))
   {
      /* have to ignore the return code, since already have an error */
      (void)zl5011xLanRxDeleteFilterMatchStructInit(zl5011xParams, &deleteFilter);

      for (loop = 0; loop < (sizeof(filters) / sizeof(zl5011xLanRxSetFilterMatchS)); loop++)
      {

         deleteFilter.matchNum = filters[loop].matchNum;

         if (deleteFilter.matchNum != (Uint32T)ZL5011X_INVALID)
         {
            /* have to ignore the return code, since already have an error */
            (void)zl5011xLanRxDeleteFilterMatch(zl5011xParams, &deleteFilter);
         }
      }
   }

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

 Description:
   Initialises structure used by zl5011xLanRxSetFilterMatch 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 zl5011xLanRxSetFilterMatchStructInit(zl5011xParamsS *zl5011xParams,
      zl5011xLanRxSetFilterMatchS *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,
            "zl5011xLanRxSetFilterMatchStructInit:",
            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;

      /* set the queues to queue 1 - the default for collecting broadcast /
         multicast etc. packets */
      par->match.ethertypeFilterEnable = ZL5011X_FALSE;
      par->match.ethertypeCpuQueue = ZL5011X_QUEUE_0;

      par->match.macAddressFilterEnable = ZL5011X_FALSE;
      par->match.macAddressCpuQueue = ZL5011X_QUEUE_0;

      /* set the number of bits to mask in the MAC address to 0. That is, the
         address is matched explicitly. */
      par->match.macAddressNumMaskBits = 0;

      par->osExclusionEnable = ZL5011X_TRUE;
   }

   return status;
}

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

 Function:
   zl5011xLanRxSetFilterMatch

 Description:
   Used to setup a packet Rx filter that is used to direct packets to the host.

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

 Structure inputs:
   matchNum       which Packet Rx filter to set - can be set to ZL5011X_INVALID
                  when any available match will be found
   match          structure to hold settings for the filter
   osExclusionEnable ZL5011X_TRUE to enable OS exclusion

 Structure outputs:
   None

 Returns:
   zlStatusE

 Remarks:
   None

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

zlStatusE zl5011xLanRxSetFilterMatch(zl5011xParamsS *zl5011xParams,
      zl5011xLanRxSetFilterMatchS *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,
            "zl5011xLanRxSetFilterMatch:",
            0, 0, 0, 0, 0, 0);

      status = zl5011xPkcFilterGetFreeEntry(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_FILTER_MATCH_IN_USE)
      {
         status = zl5011xPkcFilterDisableEntry(zl5011xParams, par->matchNum);
      }
   }

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

   /* enable the protocol if it has been set up successfully */
   if (status == ZL5011X_OK)
   {
      status = zl5011xPkcFilterEnableEntry(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)zl5011xPkcFilterDeleteEntry(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:
    zl5011xLanRxDeleteFilterMatchStructInit

 Description:
   Initialises structure used by zl5011xLanRxDeleteFilterMatch 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 zl5011xLanRxDeleteFilterMatchStructInit(zl5011xParamsS *zl5011xParams,
      zl5011xLanRxDeleteFilterMatchS *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,
            "zl5011xLanRxDeleteFilterMatchStructInit:",
            0, 0, 0, 0, 0, 0);

      par->matchNum = (Uint32T)ZL5011X_INVALID;

      par->osExclusionEnable = ZL5011X_TRUE;
   }

   return status;
}

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

 Function:
   zl5011xLanRxDeleteFilterMatch

 Description:
   Deletes a packet Rx filter.

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

 Structure inputs:
   matchNum       which filter to delete
   osExclusionEnable ZL5011X_TRUE to enable OS exclusion

 Structure outputs:
   None

 Returns:
   zlStatusE

 Remarks:
   None

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

zlStatusE zl5011xLanRxDeleteFilterMatch(zl5011xParamsS *zl5011xParams,
      zl5011xLanRxDeleteFilterMatchS *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,
            "zl5011xLanRxDeleteFilterMatch: match %d",
            par->matchNum, 0, 0, 0, 0, 0);

      status = zl5011xPkcFilterDeleteEntry(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:
    zl5011xLanRxSetProtocolMatchStructInit

 Description:
   Initialises structure used by zl5011xLanRxSetProtocolMatch function.

⌨️ 快捷键说明

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