This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

[参考译文] AM2431:AM2431如何为第2层通信设置目标 MAC 滤波器功能。

Guru**** 2510075 points
Other Parts Discussed in Thread: AM2431

请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

https://e2e.ti.com/support/microcontrollers/arm-based-microcontrollers-group/arm-based-microcontrollers/f/arm-based-microcontrollers-forum/1450619/am2431-am2431-how-to-set-destination-mac-filter-function-for-layer-2-communication

器件型号:AM2431

工具与软件:

尊敬的 TI 专家:

我正在使用 AM2431 R5F CPSW 层2 (以太网类型= 0x8805)与其他人进行通信。

我已设置端口0 Mac ={0x02、0x00、0x54、0x00、0x02、 0x03}。

我还需要接收目标 MAC = {0x03、0x00、0x54、0x00、0xFF 的消息 0xFF}、以及本身 Mac {0x02、0x00 、0x54、0x00、0x02、 0x03}。

但我收到了很多样本值消息、目标 MAC = {0x01、0x0c、0xcd、0x04、0x00、 0x00}、这会导致正常消息丢失。

如何为第2层通信设置目标 MAC 筛选功能、以便阻止样本值消息并仅接收指定的目标 MAC?

我做了一些测试,但没有使用。 仍收到所有消息。

 在 EnetApp_open ()之后调用 ENET_IOCTL (CPSW_ALE_IOCTL_SET_RX_FILTER)和 ENET_IOCTL (CPSW_ALE_IOCTL_ADD_MCAST)。

SDK 版本为: mcu_plus_sdk_am243x_09_02_00_50

操作系统:FreeRTOS

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

     

    感谢您的提问。

    我还需要接收目标地址为 Mac = {0x03、0x00、0x54、0x00、0xFF 的消息 0xff}[/报价]

    您可以参考"ALE IOCTL 命令"。 从  AM243x MCU+ SDK:CPSW 地址查找引擎(ALE)  CPSW_ALE_IOCTL_ADD_MCAST

    [quote userid="626411" url="~/support/microcontrollers/arm-based-microcontrollers-group/arm-based-microcontrollers/f/arm-based-microcontrollers-forum/1450619/am2431-am2431-how-to-set-destination-mac-filter-function-for-layer-2-communication 我收到了很多样例值消息、目标 MAC = {0x01、0x0c、0xcd、0x04、0x00、 0x00}[/报价]

    您的意思是在主机接收(R5F)?

    此致

    Ashwani

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    尊敬的 Ashwani Goel:

    您说:

    您可以参考"ALE IOCTL 命令"。 从  AM243x MCU+ SDK:CPSW 地址查找引擎(ALE)  CPSW_ALE_IOCTL_ADD_MCAST。

    LY:你没有完全看到我的问题。 我尝试了 CPSW_ALE_IOCTL_ADD_MCAST、失败了。 您能否说明 如何在 CPSW 上设置多播 Mac 过滤器的确切过程? 我们是否需要设置 RX 滤波器或添加类型?

    您的意思是在主机接收(R5F)?

    Ly:是的。  目标 Mac = {0x01、0x0c、0xcd、0x04、0x00的大量样本值消息 0x00}由其他方发送并由 R5F 接收。 但这不是我的期望。 我希望 R5F 接收 目标 MAC = {0x03、0x00、0x54、0x00、0xFF、 0xFF}或其本身 Mac {0x02、0x00、0x54、0x00、0x02、 仅限0x03}。 问题在于如何阻止此类消息。

    此致

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。
    我尝试过 CPSW_ALE_IOCTL_ADD_MCAST、失败。

    我假设您正在将以下示例转换为代码

    int enet_lwip_example(void *args)
    {
        Enet_Type enetType;
        uint32_t instId;
        int32_t status;
    
        Drivers_open();
        Board_driversOpen();
    
        DebugP_log("==========================\r\n");
        DebugP_log("      ENET LWIP App       \r\n");
        DebugP_log("==========================\r\n");
    
        EnetApp_getEnetInstInfo(CONFIG_ENET_CPSW0,
                                &enetType,
                                &instId);
    
    
        EnetAppUtils_enableClocks(enetType, instId);
        EnetApp_driverInit();
        status = EnetApp_driverOpen(enetType, instId);
    
        if (status != ENET_SOK)
        {
            EnetAppUtils_print("Failed to open ENET: %d\r\n", status);
        }
    
        EnetAppUtils_assert(status == ENET_SOK);
        {
            const uint8_t testBCastAddr[ENET_MAC_ADDR_LEN] =
            {
                0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF
            };
            EnetApp_addMCastEntry(enetType,
                                  instId,
                                  EnetSoc_getCoreId(),
                                  testBCastAddr,
                                  CPSW_ALE_ALL_PORTS_MASK);
        }

    此代码用于处理 DA =" 0xFF、0xFF、0xFF、0xFF、0xFF、0xFF、0xFF、 0xFF"

    您可以将 MC 地址的"CPSW_ALE_ALL_ALL_PORT_MASK"更改为"CPSW_ALE_ALL_MACPORTS_MASK"、然后尝试。

    如果你在这里遇到任何问题,请告诉我?

    此致

    Ashwani

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    尊敬的 

    感谢您的指导。 但在我按照建议更改代码之后、仍然会收到所有消息、而不会阻止样本值消息。

    附上源代码、希望得到您的帮助。

    int32_t EnetApp_open(EnetApp_PerCtxt *perCtxts,
                               uint32_t numPerCtxts)
    {
        uint32_t i;
        int32_t status = ENET_SOK;
    
        /* Do peripheral dependent initalization */
        EnetAppUtils_print("\nInit all peripheral clocks\r\n");
        EnetAppUtils_print("----------------------------------------------\r\n");
        for (i = 0U; i < numPerCtxts; i++)
        {
            EnetApp_PerCtxt *perCtxt = &perCtxts[i];
            EnetAppUtils_enableClocks(perCtxt->enetType, perCtxt->instId);
        }
    
        /* Create RX tasks for each peripheral */
        if (status == ENET_SOK)
        {
            EnetAppUtils_print("\nCreate RX tasks\r\n");
            EnetAppUtils_print("----------------------------------------------\r\n");
            for (i = 0U; i < numPerCtxts; i++)
            {
                EnetApp_PerCtxt *perCtxt = &perCtxts[i];
    
                EnetAppUtils_print("%s: Create RX task\r\n", perCtxt->name);
    
                EnetApp_createRxTask(perCtxt);
            }
        }
    
        /* Open Enet driver for all peripherals */
        EnetAppUtils_print("\nOpen all peripherals\r\n");
        EnetAppUtils_print("----------------------------------------------\r\n");
    
        EnetApp_driverInit();
    
        for (i = 0U; i < numPerCtxts; i++)
        {
            EnetApp_PerCtxt *perCtxt = &perCtxts[i];
            EnetApp_HandleInfo handleInfo;
    
            EnetAppUtils_print("%s: Open enet\r\n", perCtxt->name);
            status = EnetApp_driverOpen(perCtxt->enetType, perCtxt->instId);
            if (status != ENET_SOK)
            {
                EnetAppUtils_print("%s: failed to open enet\r\n", perCtxt->name);
                break;
            }
            EnetApp_acquireHandleInfo(perCtxt->enetType, perCtxt->instId, &handleInfo);
            perCtxt->hEnet = handleInfo.hEnet;
            perCtxt->hMainUdmaDrv = handleInfo.hUdmaDrv;
        }
        EnetApp_addMCastEntry(perCtxts->enetType,
                              perCtxts->instId,
                              EnetSoc_getCoreId(),
                              rollCallDstMac,
                              CPSW_ALE_ALL_MACPORTS_MASK);
    
        /* Attach the core with RM */
        if (status == ENET_SOK)
        {
            EnetAppUtils_print("\nAttach core id %u on all peripherals\r\n", gEnetApp.coreId);
            EnetAppUtils_print("----------------------------------------------\r\n");
            for (i = 0U; i < numPerCtxts; i++)
            {
                EnetApp_PerCtxt *perCtxt = &perCtxts[i];
                EnetPer_AttachCoreOutArgs attachCoreOutArgs;
    
                EnetAppUtils_print("%s: Attach core\r\n", perCtxt->name);
    
                EnetApp_coreAttach(perCtxt->enetType, perCtxt->instId, gEnetApp.coreId, &attachCoreOutArgs);
                perCtxt->coreKey = attachCoreOutArgs.coreKey;
            }
        }
    
        /* Open DMA for peripheral/port */
        if (status == ENET_SOK)
        {
            EnetAppUtils_print("%s: Open DMA\r\n", perCtxts->name);
    
            for (i = 0U; i < numPerCtxts; i++)
            {
                EnetApp_PerCtxt *perCtxt = &perCtxts[i];
    
                status = EnetApp_openDma(perCtxt, i);
                if (status != ENET_SOK)
                {
                    EnetAppUtils_print("%s: failed to open DMA: %d\r\n", perCtxts->name, status);
                }
            }
        }
    
        if (status == ENET_SOK)
        {
            status = EnetApp_waitForLinkUp(perCtxts);
            if (status != ENET_SOK)
            {
                EnetAppUtils_print("%s: Failed to wait for link up: %d\r\n", perCtxts->name, status);
            }
        }
    
        EnetAppUtils_print("%s: MAC port addr: ", perCtxts->name);
    
        EnetAppUtils_printMacAddr(&perCtxts->macAddr[0U]);
    
        return status;
    }
    void EnetApp_addMCastEntry(Enet_Type enetType,
                                      uint32_t instId,
                                      uint32_t coreId,
                                      const uint8_t *testMCastAddr,
                                      uint32_t portMask)
    {
        Enet_IoctlPrms prms;
        int32_t status;
        CpswAle_SetMcastEntryInArgs setMcastInArgs;
        uint32_t setMcastOutArgs;
    
        if (Enet_isCpswFamily(enetType))
        {
            Enet_Handle hEnet = Enet_getHandle(enetType, instId);
    
            EnetAppUtils_assert(hEnet != NULL);
            memset(&setMcastInArgs, 0, sizeof(setMcastInArgs));
            memcpy(&setMcastInArgs.addr.addr[0U], testMCastAddr,
                   sizeof(setMcastInArgs.addr.addr));
            setMcastInArgs.addr.vlanId  = 0;
            setMcastInArgs.info.super = false;
            setMcastInArgs.info.numIgnBits = 0;
            setMcastInArgs.info.fwdState = CPSW_ALE_FWDSTLVL_FWD;
            setMcastInArgs.info.portMask = portMask;
            ENET_IOCTL_SET_INOUT_ARGS(&prms, &setMcastInArgs, &setMcastOutArgs);
            ENET_IOCTL(hEnet, coreId, CPSW_ALE_IOCTL_ADD_MCAST, &prms, status);
            if (status != ENET_SOK)
            {
               DebugP_log("EnetTestBcastMcastLimit_AddAleEntry() failed CPSW_ALE_IOCTL_ADD_MCAST: %d\n",
                                   status);
            }
        }
    }
    

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

     

    您是否可以共享您发送至 AM243x 的 pcap 文件且设备正在按预期响应?

    我在从 PC 发送和确认 R5F 时遇到一些问题。

    您能否参阅以下仅位于"C:\ti\mcu_plus_sdk_am64x_10_00_00_20\examples\networking\lwip\enet_cpsw_udp_igmp"的代码库实现的 MC 地址?

    static err_t App_igmpMacFilter(struct netif *netif, const ip4_addr_t *group, enum netif_mac_filter_action action)
    {
        Enet_Handle hEnet;
        Enet_Type enetType;
        uint32_t instId;
        err_t retVal = ERR_OK;
    
        /* Convert the Mcast ip address to Mcast MacAddr */
        /* 0x01005e000000 + (ip & 0x7FFFFF) */
        uint8_t mcastMacAddr[ENET_MAC_ADDR_LEN] = IGMP_MCAST_MAC_ADDR;
    
        mcastMacAddr[3] = (uint8_t) ((ip4_addr2(group)) & 0x7f);
        mcastMacAddr[4] = (uint8_t) ip4_addr3(group);
        mcastMacAddr[5] = (uint8_t) ip4_addr4(group);
    
        EnetApp_getEnetInstInfo(CONFIG_ENET_CPSW0, &enetType,
                                &instId);
        hEnet = Enet_getHandle(enetType, instId);
    
        if (action == NETIF_ADD_MAC_FILTER)
        {
            if (EnetAppUtils_addAllPortMcastMembership(hEnet, mcastMacAddr) != ENET_SOK)
            {
                retVal = ERR_IF;
            }
        }
        else if (action == NETIF_DEL_MAC_FILTER)
        {
           if (EnetAppUtils_delAllPortMcastMembership(hEnet, mcastMacAddr) != ENET_SOK)
           {
               retVal = ERR_IF;
           }
        }
        else
        {
            EnetAppUtils_print("EnetAppUtils_igmpMacFilter failed due to invalid argument : %s\n", action);
            retVal = ERR_ARG;
        }
        return retVal;
    }

    此致

    Ashwani

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    尊敬的 Ashwani Goel:

    请查找 pcap file.e2e.ti.com/.../Packets.zip 的附件

    我的设备连接为:

       AM2431 板收到3种类型的消息:

    主板多播 msg:src: 02:00:54:00:01:00 dst:03:00:54:00:ff:ff Ethertype=0x8805、AM2431板应接收它。

    主板 单播消息: src: 02:00:54:00:01 :00 dst:02:00:54:00:01:03 ethertype=0x8805、AM2431板应接收。

    其它 板 组播消息: src: 02:00:54:00  :40:02 dst:01:0c:CD:04:00:00 Ethertype=0x88ba、AM2431板不应接收 。

    BR

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。
    其它 主板 多播 msg: src: 02:00 :54:00 :40:02 dst:01:0c:CD:04:00:00 Ethertype=0x88ba、AM2431主板不应收到 它。

    它应在以下代码中测试 MC 滤波器时正常工作。

    您能否参考以下代码库实施的 MC 地址、该地址仅位于"C:\ti\mcu_plus_sdk_am64x_10_00_00_20\examples\networking\lwip\enet_cpsw_udp_igmp"?[/quote"

    您还可以使用"ethertype=0x8805" 而不是"ethertype=0x88ba"来尝试其他操作吗?

    此致

    Ashwani

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    你好、Ashwani

    我在此处的示例代码中找不到如何更改以太网类型。

    SDK 中的枚举不包含此以太网类型。

    客户还反馈、他们无法更改 Ethertype、因为这是其自定义软件包。

    您能否分享如何集成示例代码以实现 Mac 过滤器? 谢谢

    此致

    Zekun

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    你好、凌云

    此函数用于添加需要滤除的地址。

    EnetApp_addMCastEntry (enetType、
    instId、
    EnetSoc_getCoreId()、
    testBCastAddr、
    CPSW_ALE_ALL_ALL_PORTS_MASK);

    因此、您需要将  testBCastAddr 更改为 01:0c:CD:04:00:00

    并将掩码更改为 CPSW_ALE_ALL_MACPORTS_MASK

    然后、您不应该从 其它   主板组播消息接收数据包、但可以从主板组播消息和 主板 单播消息接收数据包。

    此致

    Zekun

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    尊敬的 Zekun:

    感谢您对 EnetApp_addMCastEntry ()函数的准确描述。 我尝试将  testBCastAddr 更改为 01:0c:CD:04:00:00。

    但没有用、AM2431电路板仍然收到所有消息、包括样本值消息。

    附件是源 code.e2e.ti.com/.../l2_5F00_cpsw_5F00_cfg.c

    此致、

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    你好、凌云

    您调用的这个函数的 enetType 值是什么?

    EnetApp_addMCastEntry (perCtxts->enetType
                 perCtxts->instId
                 EnetSoc_getCoreId()
                 svDstMac、
                 CPSW_ALE_ALL_MACPORTS_MASK);
    你好、 Ashwani
    对此有什么想法吗?
    此致
    Zekun
  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    perCtxts->enetType ENET_CPSW_3G

    perCtxts->instId = 0

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。
    您调用的这个函数的 enetType 值是什么?

    这是以太网外设类型。

    有关  更多详细信息、请参阅 AM243x MCU+ SDK:enet_types.h 源文件。

    此致

    Ashwani

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    尊敬的 Yang:

    附件是源代码。

    您仍在使用"cpsw_ale_all_ports_mask"

    对于特定的 MAC 地址、尝试使用"CPSW_ALE_ALL_MACPORTS_MASK"、但不希望在主机上接收。

    并将掩码更改为 CPSW_ALE_ALL_MACPORTS_MASK[/QUOT]

    此致

    Ashwani

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    尊敬的 Ashwani&Zekun:

    如您所说、Mac 过滤器功能现在可以工作了。 我不明白 CPSW_ALE_ALL_ALL_MACPORTS_MASK 和 CPSW_ALE_ALL_PORT_MASK 的含义、因此我忽略了错误。

    感谢您的支持!