sl_recv hangs from time to time on RAW socket
응답
17. 3. 7 오후 5:10

Hi Community,

 

I have a problem using RAW sockets over WiFi connecting a XDK with a Raspberry Pi. This usually runs quite smoothly, but from time to time (after a random period of run time), I can no longer receive packets. Wireshark, which is listening on WiFi at another PC, prooves that the R'Pi is keeps on transmitting well-formatted packets. Hunting down the error, I found out that sl_Recv(sd,..) freezes, although I set up the socket to have a timeout of 20 ms. And I allocated a sufficiently large amount of receive buffer for sl_Recv(.).

My socket setup looks like:

uint32_t num_frames = 1;
uint32_t ipheader = 0;
static SlRateIndex_e rate =  1; // WiFi module's data rate index
static uint32_t tx_power  = 15;
static uint32_t preamble  =  0;
static uint32_t channel   = 13;

_i16 sd = sl_Socket(SL_AF_RF, SL_SOCK_RAW, 0);
_i16 status = sl_SetSockOpt(sd, SL_SOL_PHY_OPT, SL_SO_PHY_RATE, &rate, sizeof(_u32));
status &= sl_SetSockOpt(sd, SL_SOL_PHY_OPT, SL_SO_PHY_TX_POWER, &tx_power, sizeof(_u32));
status &= sl_SetSockOpt(sd, SL_SOL_PHY_OPT, SL_SO_PHY_NUM_FRAMES_TO_TX, &num_frames, sizeof(_u32));
status &= sl_SetSockOpt(sd, SL_SOL_PHY_OPT, SL_SO_PHY_PREAMBLE, &preamble, sizeof(_u32));
status &= sl_SetSockOpt(sd, SL_SOL_SOCKET, SL_IP_HDRINCL, &ipheader, sizeof(_u32));
status &= sl_SetSockOpt(sd, SL_SOL_SOCKET, SL_SO_CHANGE_CHANNEL, &channel, sizeof(_u32));

struct SlTimeval_t timeVal;
timeVal.tv_sec =  0;     // Seconds
timeVal.tv_usec = 20000; // Microseconds. 10000 microseconds resolution
status&=sl_SetSockOpt(sd,SL_SOL_SOCKET,SL_SO_RCVTIMEO, (_u8 *)&timeVal, sizeof(timeVal));

Do you have any idea/experience how this could happen? Any hint how to debug this issue?

Best,

Stephan

0 (0 투표)
RE: sl_recv hangs from time to time on RAW socket
응답
17. 3. 8 오후 4:56 as a reply to Stephan Ludwig.

Hello Stephan,

if you initialize the sl_Recv() receive function as blocking with a timeout, it should not freeze more than 20 ms.

Like you already metioned, I do not guess this is an issue related to the WiFi or raspberry pi.

This seems to me like a memory management or configuration issue since the issue only occurs occasional. I would recommend to step through your code with a JLINK debugger to detect the cause of getting stuck in the receiving function.

I am not sure about your use case, but as temporary workaround, a watchdog integration could be helpful to force to XDK to restart when freezing.

Kind regards,
Manuel

0 (0 투표)
RE: sl_recv hangs from time to time on RAW socket
응답
17. 3. 9 오후 1:55 as a reply to Manuel Cerny.

Hi Manuel,

thank you a lot for your help. In deed I attached a debugger. However the issue is hard to debug as the error occurs only randomly. Now, I think I narrowed it down to the following: It seems like sl_recv gets stuck in _SlDrvMsgRead. If I pause debugging, I often end up in this function called by this stack

_SlDrvRxHdrRead() at driver.c:1.597 0x2be08    
_SlDrvMsgRead() at driver.c:964 0x2b1ac    
_SlDrvMsgReadSpawnCtx() at driver.c:1.424 0x2bc00    
WlanDriver_SimpleLinkSpawnTask() at WlanDriver.c:438 0x2e53a   

 I do not understand, why WlanDriver_SimpleLinkSpawnTask is called (I guess it is by the scheduler?), but it seems like the process is running endlessly(?) in this while loop:

static _SlReturnVal_t _SlDrvRxHdrRead(_u8 *pBuf, _u8 *pAlignSize)
...
/* read while first 4 bytes are different than last 4 bytes */
while ( *(_u32 *)&pBuf[0] == *(_u32 *)&pBuf[4])
{
     NWP_IF_READ_CHECK(g_pCB->FD, &pBuf[4], 4);
}

Any further ideas?

Best, Stephan

PS: A watchdog is not an option as a restart will also kill the state of my state machine.

0 (0 투표)
RE: sl_recv hangs from time to time on RAW socket
응답
17. 3. 9 오후 2:13 as a reply to Stephan Ludwig.

Addendum: I am not using any dynamic memory allocation in my code, so I cannot imagine that it is a memeory issue - unless I am running out of memory (heap, stack). How can I check that?

/SL

0 (0 투표)
RE: sl_recv hangs from time to time on RAW socket
응답
17. 3. 13 오전 10:20 as a reply to Stephan Ludwig.

Hello Stephan,

Unfortunately, I am not quite sure how to solve this immediately.

I guess this issues requires further analysis and I really would like to reproduce it.

Would you be so kind and share your application code with me? Thus I would ask you to post you email address in there that I can contact you.

Kind regards,
Manuel

0 (0 투표)
RE: sl_recv hangs from time to time on RAW socket
응답
17. 3. 23 오전 10:43 as a reply to Manuel Cerny.

Hi Manuel,

 

I already sent you an E-Mail. My address is stephan.ludwig2@de.bosch.com ;-)

Best,

Stephan

0 (0 투표)
RE: sl_recv hangs from time to time on RAW socket
응답
17. 3. 23 오후 5:33 as a reply to Stephan Ludwig.

Hello Stephan,

thank you very much. 
I apologize the inconvenience for sharing your email address twice.

I will keep all other users in the community posted about the progress in this thread.

Kind regards,
Manuel

0 (0 투표)