<commit_before>#include "libs/CdcEem/cdc_eem.h"

#include "libs/base/utils.h"
#include "libs/nxp/rt1176-sdk/usb_device_cdc_eem.h"
#include "third_party/nxp/rt1176-sdk/middleware/lwip/src/include/netif/ethernet.h"

extern "C" {
#include "third_party/nxp/rt1176-sdk/middleware/wiced/43xxx_Wi-Fi/app/dhcp_server.h"
}

#include <memory>

#define DATA_OUT (1)
#define DATA_IN  (0)

namespace valiant {

std::map<class_handle_t, CdcEem*> CdcEem::handle_map_;

CdcEem::CdcEem() {}

void CdcEem::Init(uint8_t bulk_in_ep, uint8_t bulk_out_ep, uint8_t data_iface) {
    bulk_in_ep_ = bulk_in_ep;
    bulk_out_ep_ = bulk_out_ep;
    cdc_eem_data_endpoints_[DATA_IN].endpointAddress = bulk_in_ep | (USB_IN << 7);
    cdc_eem_data_endpoints_[DATA_OUT].endpointAddress = bulk_out_ep | (USB_OUT << 7);
    cdc_eem_interfaces_[0].interfaceNumber = data_iface;
    tx_semaphore_ = xSemaphoreCreateBinary();

    if (!utils::GetUSBIPAddress(&netif_ipaddr_)) {
        IP4_ADDR(&netif_ipaddr_, 10, 10, 10, 1);
    }
    IP4_ADDR(&netif_netmask_, 255, 255, 255, 0);
    IP4_ADDR(&netif_gw_, 0, 0, 0, 0);
    netifapi_netif_add(&netif_, &netif_ipaddr_, &netif_netmask_, &netif_gw_, this, CdcEem::StaticNetifInit, ethernet_input);
    netifapi_netif_set_default(&netif_);
    netifapi_netif_set_link_up(&netif_);
    netifapi_netif_set_up(&netif_);
    start_dhcp_server(netif_ipaddr_.addr);
}

err_t CdcEem::StaticNetifInit(struct netif *netif) {
    CdcEem *instance = reinterpret_cast<CdcEem*>(netif->state);
    return instance->NetifInit(netif);
}

err_t CdcEem::NetifInit(struct netif *netif) {
    netif->name[0] = 'u';
    netif->name[1] = 's';
    netif->output = etharp_output;
    netif->linkoutput = CdcEem::StaticTxFunc;
    netif->mtu = 300;
    netif->hwaddr_len = 6;
    netif->flags = NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP;

    netif->hwaddr[0] = 0x00;
    netif->hwaddr[1] = 0x1A;
    netif->hwaddr[2] = 0x11;
    netif->hwaddr[3] = 0xBA;
    netif->hwaddr[4] = 0xDF;
    netif->hwaddr[5] = 0xAD;

    return ERR_OK;
}

err_t CdcEem::StaticTxFunc(struct netif *netif, struct pbuf *p) {
    CdcEem *instance = reinterpret_cast<CdcEem*>(netif->state);
    return instance->TxFunc(netif, p);
}

err_t CdcEem::TxFunc(struct netif *netif, struct pbuf *p) {
    std::unique_ptr<uint8_t> combined_pbuf(nullptr);
    uint8_t *tx_ptr = nullptr;
    uint32_t tx_len = p->tot_len;
    if ((p->next == NULL) && (p->tot_len == p->len)) {
        tx_ptr = reinterpret_cast<uint8_t*>(p->payload);
    } else {<commit_msg>CdcEem: add NETIF_FLAG_IGMP to netif flags<commit_after>#include "libs/CdcEem/cdc_eem.h"

#include "libs/base/utils.h"
#include "libs/nxp/rt1176-sdk/usb_device_cdc_eem.h"
#include "third_party/nxp/rt1176-sdk/middleware/lwip/src/include/netif/ethernet.h"

extern "C" {
#include "third_party/nxp/rt1176-sdk/middleware/wiced/43xxx_Wi-Fi/app/dhcp_server.h"
}

#include <memory>

#define DATA_OUT (1)
#define DATA_IN  (0)

namespace valiant {

std::map<class_handle_t, CdcEem*> CdcEem::handle_map_;

CdcEem::CdcEem() {}

void CdcEem::Init(uint8_t bulk_in_ep, uint8_t bulk_out_ep, uint8_t data_iface) {
    bulk_in_ep_ = bulk_in_ep;
    bulk_out_ep_ = bulk_out_ep;
    cdc_eem_data_endpoints_[DATA_IN].endpointAddress = bulk_in_ep | (USB_IN << 7);
    cdc_eem_data_endpoints_[DATA_OUT].endpointAddress = bulk_out_ep | (USB_OUT << 7);
    cdc_eem_interfaces_[0].interfaceNumber = data_iface;
    tx_semaphore_ = xSemaphoreCreateBinary();

    if (!utils::GetUSBIPAddress(&netif_ipaddr_)) {
        IP4_ADDR(&netif_ipaddr_, 10, 10, 10, 1);
    }
    IP4_ADDR(&netif_netmask_, 255, 255, 255, 0);
    IP4_ADDR(&netif_gw_, 0, 0, 0, 0);
    netifapi_netif_add(&netif_, &netif_ipaddr_, &netif_netmask_, &netif_gw_, this, CdcEem::StaticNetifInit, ethernet_input);
    netifapi_netif_set_default(&netif_);
    netifapi_netif_set_link_up(&netif_);
    netifapi_netif_set_up(&netif_);
    start_dhcp_server(netif_ipaddr_.addr);
}

err_t CdcEem::StaticNetifInit(struct netif *netif) {
    CdcEem *instance = reinterpret_cast<CdcEem*>(netif->state);
    return instance->NetifInit(netif);
}

err_t CdcEem::NetifInit(struct netif *netif) {
    netif->name[0] = 'u';
    netif->name[1] = 's';
    netif->output = etharp_output;
    netif->linkoutput = CdcEem::StaticTxFunc;
    netif->mtu = 300;
    netif->hwaddr_len = 6;
    netif->flags = NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP | NETIF_FLAG_IGMP;

    netif->hwaddr[0] = 0x00;
    netif->hwaddr[1] = 0x1A;
    netif->hwaddr[2] = 0x11;
    netif->hwaddr[3] = 0xBA;
    netif->hwaddr[4] = 0xDF;
    netif->hwaddr[5] = 0xAD;

    return ERR_OK;
}

err_t CdcEem::StaticTxFunc(struct netif *netif, struct pbuf *p) {
    CdcEem *instance = reinterpret_cast<CdcEem*>(netif->state);
    return instance->TxFunc(netif, p);
}

err_t CdcEem::TxFunc(struct netif *netif, struct pbuf *p) {
    std::unique_ptr<uint8_t> combined_pbuf(nullptr);
    uint8_t *tx_ptr = nullptr;
    uint32_t tx_len = p->tot_len;
    if ((p->next == NULL) && (p->tot_len == p->len)) {
        tx_ptr = reinterpret_cast<uint8_t*>(p->payload);
    } else {
{'fraction_non_alphanumeric': 0.14508796204783553, 'fraction_numerical': 0.02925479343743823, 'mean_word_length': 4.634743875278397, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 59, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5358445', 'n_tokens_mistral': 2283, 'n_tokens_neox': 2188, 'n_words': 316}