Goodmorning,
I'm working to create a system to communicate with raw sockets. I've built all the sample projects with pdkProjectCrate.bat and I've taken the NIMU_BasicExample_bbbAM335x_armExampleproject as starting point. Reading the document NDK_API_Reference.html, the file C:\ti\ndk_3_61_01_01\packages\ti\ndk\inc\serrno.h and some TI threads, below you can see thread used to initialize the sockets.
I'm getting the following response:
Jumping to StarterWare Application...
SetPhyMode:000021e1 Auto:1, FD10:64, HD10:32, FD100:256, HD100:128, FD1000:8192 LPBK:0
Starting app to test raw sockets!
SetPhyMode:000021e1 Auto:1, FD10:64, HD10:32, FD100:256, HD100:128, FD1000:8192 LPBK:0
error in rx device setsockopt: 22
ENETPHY_FindingState: PhyNum: 0
ENETPHY_FindingState: PhyNum: 0
ENETPHY_DisablePhy(0)
Enable Phy to negotiate external connection
NWAY Advertising: FullDuplex-1000 FullDuplex-100 HalfDuplex-100 FullDuplex-10 HalfDuplex-10
ENETPHY_DisablePhy(0)
Enable Phy to negotiate external connection
NWAY Advertising: FullDuplex-1000 FullDuplex-100 HalfDuplex-100 FullDuplex-10 HalfDuplex-10
Phy: 0, NegMode 01e1, NWAYadvertise 01e1, NWAYREadvertise 45e1
Negotiated connection: FullDuplex 100 Mbs
void test()
{
UART_printf("Starting app to test raw sockets!\n");
while(1)
{
int r, val;
static MACHINE_STATES machineStates = INIT_MACHINE;
switch(machineStates)
{
case INIT_MACHINE:
fdOpenSession(TaskSelf());
prxsock = socket(AF_RAWETH, SOCK_RAWETH, 0x400);
if (prxsock == INVALID_SOCKET) {
UART_printf("\nFailed to create RX RAW socket: %d\n", fdError());
fdCloseSession(TaskSelf());
machineStates = ERROR_DATA;
break;
}
// configure the receive device
val = 1;
r = setsockopt(prxsock, SOL_SOCKET, SO_IFDEVICE, &val, sizeof(val));
if(r < 0) {
UART_printf("error in rx device setsockopt: %d\n", fdError());
fdCloseSession(TaskSelf());
machineStates = ERROR_DATA;
break;
}
// Configure the EMAC channel number
val = 3;
r = setsockopt(prxsock, SOL_SOCKET, SO_PRIORITY, &val, sizeof(val));
if(r < 0) {
UART_printf("error in rx emac setsockopt: %d\n", fdError());
fdCloseSession(TaskSelf());
machineStates = ERROR_DATA;
break;
}
// Configure the Receive buffer size
val = 1000;
r = setsockopt(prxsock, SOL_SOCKET, SO_RCVBUF, &val, sizeof(val));
if(r < 0) {
UART_printf("error in rx setsockopt: %d\n", fdError());
fdCloseSession(TaskSelf());
machineStates = ERROR_DATA;
break;
}
// we use RAW packet socket, with packet type ETH_P_ECAT
ptxsock = socket(AF_RAWETH, SOCK_RAWETH, 0x400);
if (ptxsock == INVALID_SOCKET) {
UART_printf("\nFailed to create TX RAW socket: %d\n", fdError());
fdCloseSession(TaskSelf());
machineStates = ERROR_DATA;
break;
}
// configure the transmit device
val = 1;
r = setsockopt(ptxsock, SOL_SOCKET, SO_IFDEVICE, &val, sizeof(val));
if(r < 0) {
UART_printf("error in tx device setsockopt: %d\n", fdError());
fdCloseSession(TaskSelf());
machineStates = ERROR_DATA;
break;
}
// Configure the EMAC channel number
val = 3;
r = setsockopt(ptxsock, SOL_SOCKET, SO_PRIORITY, &val, sizeof(val));
if(r < 0) {
UART_printf("error in tx emac setsockopt: %d\n", fdError());
fdCloseSession(TaskSelf());
machineStates = ERROR_DATA;
break;
}
// Configure the Transmitter buffer size
val = 1000;
r = getsendncbuff(ptxsock, val, (void **) &pBuffer, &hPkt);
if(r < 0) {
UART_printf("error in tx setsendbuf: %d\n", fdError());
fdCloseSession(TaskSelf());
machineStates = ERROR_DATA;
break;
}
UART_printf("\nSockets Initialized!\n");
fdCloseSession(TaskSelf());
machineStates = SEND_DATA;
break;
case SEND_DATA:
composePacket();
osal_usleep(100);
break;
case RECEIVE_DATA:
//decodePacket();
break;
case ERROR_DATA:
osal_usleep(1000);
break;
default:
break;
}
}
}
/* ========================================================================== */
/* Main Function */
/* ========================================================================== */
int main()
{
/* Call board init functions */
Board_initCfg boardCfg;
EMAC_HwAttrs_V4 cfg;
boardCfg = BOARD_INIT_PINMUX_CONFIG |
BOARD_INIT_MODULE_CLOCK | BOARD_INIT_UART_STDIO;
Board_init(boardCfg);
/* Chip configuration MII/RMII selection */
SOCCtrlCpswPortMacModeSelect(1, ETHERNET_MAC_TYPE_MII);
SOCCtrlCpswPortMacModeSelect(2, ETHERNET_MAC_TYPE_MII);
EMAC_socGetInitCfg(0, &cfg);
cfg.port[0].phy_addr = EMAC_CPSW_PORT0_PHY_ADDR_EVM;
cfg.port[1].phy_addr = EMAC_CPSW_PORT0_PHY_ADDR_EVM;
cfg.macModeFlags = EMAC_CPSW_CONFIG_MODEFLG_FULLDUPLEX;
EMAC_socSetInitCfg(0, &cfg);
NIMUDeviceTable[nimu_device_index++].init = &CpswEmacInit ;
NIMUDeviceTable[nimu_device_index].init = NULL ;
osal_thread_create(&test, 0);
BIOS_start();
return -1;
}
My questions are:
- Is the NIMU_basic example the more suitable project to start with raw sockets? If not, can you provide an up-to-date example?
- Is there an application (.exe) that can be used to test the sockets?
- Is it possible to connect sockets in loop (I read what I write)?
- Why do I get error 22 (NDK_EINVAL /* Invalid argument */) when crating raw_socket?
- Once that I created the read and write sockets can I call the method sendncfree() and recvncfree() only when closing the sockets ? It's not necessary to allocate space and deallocate every time that I call methods sendnc and recvnc, right?
Thank you.
Best Regards,
Davide Brunelli
Best Regards,
Davide Brunelli
