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.

What Protocal canbe filled in socket funtion when use NDK if just want to use raw ethernet?

Hi all,

Actrually I am trying to port Ethercat Master to Sitara processor.The low level driver (EMAC) just want to use the EMAC of the NDK. But when I try to new a socket by using the function "SOCKET socket( int domain, int type, int protocol );" I met with problems:

1. The domain ,can I use "AF_RAWETH"?

2.The type,can I use "SOCK_RAW"?

3.The protocal phase is a problem,cause the NDK now not support EtherCAT ofcourse,But what can I set here if I just let other code to handle this and use a truly "raw" EMAC function here?

  • Hi Bin Hu1,

    Yes, the NDK supports raw sockets and you can create a raw socket just how you guessed.

    Once you create a raw socket, you will be able to receive "non standard" packets (i.e. Ethernet frame with 'type' field other than IPv4/v6 or ARP) in your application through the raw socket.  Such a frame is passed to the raw module, which then writes it into the socket buffer.

    So, you can write your application to handle whatever protocol you want.  You would just get the data from the socket and decode it according to the protocol.

    Now for the driver, my understanding is that you may need to configure the driver to be in promiscuous mode.  But I would have to let the Sitara Team help you with how to do that part.

    Steve

  • Hi Steve,

    Thank you first for your quick response! Actrually after I take the refense from os_drive source fold.I think I have succeed to carryout the NIMURegister command to register the hardware to NDK.

    But when I try to use socket function to new a socket to begin the communication, I always failed. The result of the socket function is always INVALID_SOCKET(0xFFFF FFFF). How can I make the next step?

    Thank you!

  • Bin Hu1,

    If the socket function is failing, it could be due to a few different reasons.  You should call the function 'fdError()' to get the error code that is being flagged.  You can then check that error code with the constants defined in ti/ndk/inc/serrorno.h.

    Please refer to the NDK API guide (spru524h.pdf) for information on the sockets APIs.  Also, if you haven't read the NDK User's Guide (spru523h.pdf) and the NDK driver design guide (sprufp2_nspethdrvdesign.pdf)I would highly recommend these, too.

    All of these documents are located in the docs directory of your NDK installation.

    Steve

  • Hello Steve,

    Thanks. Actrually I have already read these files.Also I tried the fdError command. The error code I got is 9-EBADF(Bad file discriptor).

    I already called the fdOpenSession before I call socket but still met this error. So I got confused.