SocketCan device stops sending messages after a specific amount of messages have been sent - socketcan

I'm using a canable CAN-to-USB adapter to communicate with a CAN bus. To initialize the SocketCan device, I'm using the following command:
slcand -c -o -f -s6 /dev/ttyACM0
and
ifconfig slcan0 up
The CAN bus is operating at 500KHz. I can transmit and read messages fine for a while. But after sending and receiving for a few minutes, I can no longer send messages but can still receive.
This is the output of ip -details -statistics link show slcan0:
469: slcan0: <NOARP,UP,LOWER_UP> mtu 16 qdisc fq_codel state UNKNOWN mode DEFAULT group default qlen 10
link/can promiscuity 0 numtxqueues 1 numrxqueues 1 gso_max_size 65536 gso_max_segs 65535
RX: bytes packets errors dropped overrun mcast
179974 24437 0 0 0 0
TX: bytes packets errors dropped carrier collsns
136 17 0 0 0 0
If I disconnect the device, plug it back in, and run the slcand command again, it works.

I have similar problems with my CANAble. I've been having better luck with the CandleLight Firmware, see CANAble Getting Started about halfway down the page for "Alternative Firmware".
I still have problems with my CANAble not sending messages (receive still works) every once in a while, but it's much less frequent after the firmware upgrade. When that happens, I just need to take down the interface and bring it back up, no need to unplug.
Also, you can try increasing the txqueulen to something like 10,000. That seems to work for some people, but I still get occasional lockups.
sudo ifconfig slcan0 txqueuelen 10000

Related

Can I just run one port to send packet continuously in Pktgen?

I want to accomplish to send packet continuously in port "0",and I have done some configuraition:
./app/x86_64-native-linuxapp-gcc/pktgen -l 0-2 -n 4 --proc-type auto --socket-mem 1024 -b 00:08.0 -- -P -m "[1].0"
and in the interactive CLI I set something:
Pktgen>set 0 src ip "192.168.12.2/24"
Pktgen>set 0 dst ip "192.168.12.3"
Pktgen>set 0 proto udp
Pktgen>set 0 count 0
Pktgen>set 0 rate 50
Pktgen>set 0 size 64
Pktgen>start 0
But according to the page main display, the port 0 just transmit few packets and stop to send packet anymore,even I stop 0 and start 0 again, there is no any response.
Pktgen must config two dpdk ports? when I config two dpdk ports and run scripts/rfc2544_tput_test.lua, it works well,I want to know why...
Yes, you can. It work seamlessly. Only requirement, the other side should be able to detect link state change.

GSM Telit GL865-QUAD AT command, error: 314 (SIM card busy)

I'm trying to communicate with GSM click module (Telit GL865-QUAD module) via UART with AT command. First I want to read all received messages, but for some reason I got error 314, meaning that SIM card is busy. Other answers from GSM are ok.
So this is my config (sending few at commands in a row):
AT\r\n (check GSM)
ATE0\r\n (echo disable)
AT+CMGF=1\r\n (set SMS text mode)
AT+IPR?\r\n (query current baud rate)
AT+CMGL=\"ALL\"\r\n (finally read all messages)
All commands have 1 second delay after gsm get positive (OK) answer. For example: send AT\r\n wait for OK and then wait 1 second; after that delay send another AT command.
Result: I got fine response from GSM when I sent first 4 AT command. But after the fifth one the modem returns error 310 (sometimes) followed by error 314:
AT+CMGL="ALL"
+CMS ERROR: 310
AT+CMGL="ALL"
+CMS ERROR: 314\r\n
I tried it with 2 different SIM cards and got same result.
Any idea or comment are welcome.
First of all, GE865-QUAD is an old device, so I recommend that you at least update it to the latest FW version. You can query current FW version of any GSM modem by issuing AT+CGMR AT command.
Edit: since you have a really old version (10.00.144 is dated 2009/2010!) I STRONGLY recommend updating it, since many bugs could have been fixed since then. You will be able to get last version from Telit site, and to flash it via UART.
Errors explanation
You seem to obtain error 314 preceeded, sometimes by error 310.
+CMEE Error: 314 means SIM busy, as correctly stated by your question subject
+CMEE Error: 310 means SIM not inserted
Possible solutions
First of all, make sure that the SIM is correctly inserted. It has to be pushed all its way in. I suppose you correctly inserted it, but a check has to be done.
Then, since you state that
I try with 2 sim cards and got same result.
I suggest you to check the contacts of the SIM holder (because it is unlikely that both your SIMs have bad electric contacts). In fact the SIM busy status, usually reached when a SIM is actually read (e.g. full phonebook) could also mean that some unconsistent action happened (also SIM failure massage can be shown in those cases).
Make sure you wait enough for SIM ready. In fact, even if SIM initialization usually takes less than a second, in some old SIM models might happen that a longer time is needed.
Telit provides a command to query SIM status: AT#QSS. As descripted by the AT guide, it enables an unsolicited message for any SIM status change. But it also allows allows, through its read command to query the status asynchronously:
AT#QSS?
Read command reports whether the unsolicited indication #QSS is currently enabled or not, along with the SIM status, in the format:
#QSS: mode,status
mode - the verbosity level of #QSS URC, set with AT#QSS=mode. Default value is 0; 2 enables the maximum verbosity level.
status - current SIM status
0 - SIM NOT INSERTED
1 - SIM INSERTED
2 - SIM INSERTED and PIN UNLOCKED (Note: available only if mode=2!)
3 - SIM INSERTED and READY (SMS and Phonebook access are possible) (Note: available only if mode=2!)
So you have to wait until status 3 is reached. I suggest issuing read command every 1/2 seconds until the desired status is reached. Issuing commands that involve the SIM storage before that status is reached will lead to SIM Busy error.
Very important: since status=3 will be shown only with mode=2, issue the following concatenated AT command in order to discover if the SIM INSERTED and READY status has been actually received without enabling URCs:
AT#QSS=2;#QSS?;#QSS=0
In this way, mode=2 is set just before the read command so that the full status list is supported. Then mode is restored to value 0, avoiding URCs to appear.
Make sure that the PIN has been inserted!
The SIM could be locked with the PIN code. Verify it by querying AT+CPIN?. If the response is +CPIN: SIM Ready you are fine. Otherwise, If the response is +CPIN: SIM PIN, you have to insert the PIN code by issuing
AT+CPIN=<PIN>
I found what was problem. Power supply for GSM did not have enough Amps.. For GSM you must provide 3.3V and 3A from power supply unit. GSM don't have 6.5W power consumption if you think that GSM need 3A all the time. GSM have peaks of current up to 2A and thats why you need more Amps.

How to fix MEMP_SYS_TIMEOUT in sntp client on stm32

On an STM32H7, I run LwIP, to learn more about raw API (NOSYS = 1).
Now, UDP (and TCP) server and client work just fine.
I'm next setting up an NTP client.
I initialize it this way (in sntp_client.c):
#define SNTP_CONF_IPADDR0 185
#define SNTP_CONF_IPADDR1 255
#define SNTP_CONF_IPADDR2 55
#define SNTP_CONF_IPADDR3 20
sntp_setoperatingmode(SNTP_OPMODE_POLL);
sntp_setservername(0, (char*)"pool.ntp.org");
sntp_init();
After start, I get the error
Assertion "sys_timeout: timeout != NULL, pool MEMP_SYS_TIMEOUT is empty"
failed at line 212 in
..\..\..\Middlewares\Third_Party\LwIP\src\core\timeouts.c
In Wireshark, I see no NTP packages are traced.
In sntp_init, sntp_request(NULL); is called, after which the time-out shows up.
What do I need to check next?
My source is here, the important part in in sntp_client.c:
https://github.com/bkht/LAN8742A_KSZ8851SNL_LwIP

Are packetdrill tests portable?

Recently I had to write tests using the excellent google's packetdrill tool. (https://github.com/google/packetdrill)
To summarize, it's a tool that can test the TCP(or IP or UDP) stack of our computer just by writing some test cases that combines C commands, expected outbound and inbound packets.
But, I can't figure out how portable those tests are. For instance, if I run the tests on the github directory, nearly all of those fail.
Let's take this one fr-4pkt-sack-linux.pkt:
// Test fast retransmit with 4 packets outstanding, receiver sending SACKs.
// In this variant the receiver supports SACK.
// Establish a connection.
0 socket(..., SOCK_STREAM, IPPROTO_TCP) = 3
+0 setsockopt(3, SOL_SOCKET, SO_REUSEADDR, [1], 4) = 0
+0 bind(3, ..., ...) = 0
+0 listen(3, 1) = 0
+0 < S 0:0(0) win 32792 <mss 1460,sackOK,nop,nop,nop,wscale 10>
+0 > S. 0:0(0) ack 1 <mss 1460>
+.1 < . 1:1(0) ack 1 win 257
+0 accept(3, ..., ...) = 4
// Send 1 data segment and get an ACK, so cwnd is now 4.
+0 write(4, ..., 1000) = 1000
+0 > P. 1:1001(1000) ack 1
I get the following error:
fr-4pkt-sack-linux.pkt:19: error handling packet: live packet field ipv4_total_length: expected: 1040 (0x410) vs actual: 297 (0x129)
script packet: 0.100283 P. 1:1001(1000) ack 1
actual packet: 0.100277 P. 1:258(257) ack 1 win 29200
It seems to indicate that my computer (which is a 64bits Ubuntu gnome 16.04) sends only 257 bytes instead of 1000 for the first packet (the window scaling argument is simply ignored).
If I run other tests, such as sack-shift-sacked-1-2-3-fack.pkt, it seems to indicate that the wscale argument is ignored by my computer.
So, my questions are:
Is that normal to ignore the wscale argument? Is my computer behaving strangely?
If it's normal (like it's some specific linux TCP feature), how can we ensure that the packetdrill tests that run on my computer will run on some other computer?
Thank you in advance
The solution was very simple but I'll keep this topic for those who are in the same situation.
In fact, I simply disabled TCP windows scaling via sysctl.
I used a configuration file here: http://cnp3book.info.ucl.ac.be/2nd/html/_downloads/sysctl-cnp3.conf
I changed variables with sysctl -w variable but I wasn't aware that those changes were persistent after rebooting computer.
So, don't make the same mistake as I've done: be careful when using sysctl, it can break your entire computer (if you forget to reset those settings after your tests).
After resetting to default, it now works perfectly. So, the portability of packetdrill tests seems ok (if there's no new major TCP feature).

How can I have DNS name resolving running while other protocols seem to be down?

We are trying to implement a software based on Moxa UC-7112-LX embedded computer (uClinux OS). We use Cinteron MC52i GSM modem (regular GPRS service) and standart pppd to connect to the Internet.
Everything seems to be fine, right after the connection. Ping utility is working, Socket functions in my program work normally too. However after some time ppp connection brokes in a very peculiar way. These are the symptoms of that situation:
When I call ping utility with some host name as parameter the system is able to resolve it's IP and starts sending ICMP packets but gets no response. I am trying different web resources names, so that the system cannot have their addresses cached or something. Whatever I choose, the system correctly resolves IP but can't get any ping responce.
connect() and write() functions in my application give no error return but when it comes to read() the function returns with errno set to ECONNRESET (Connection reset by peer). The program uses standard socket functions (TCP protocol)
the ppp link is shown as running (ifconfig ppp0)
So, the situation that I have is: the link is good enough to maintain DNS resolving service (UDP is working?) but NOT good enough to run TCP connection and receive ping echoes...
The situation does not appear all the time. Sometimes the system can work normally for days without any problem. Whenever the problem appears, simple reset solves everything.
I know that the system we use is quite exotic, and the situation described here may be connected with some buggy tcp stack or pppd implementation. Considering that the system is preconfigured by the manufacturer I don't have any options to rebuild/change the OS firmware.
Still I hope that someone have seen the similar situation on any linux-like system. Is there any way to test why DNS name resolving is working while the other network stuff does not? Is it possible to remove such connection state with some pppd settings?
Edit:
First of all, I'd like to address the possibility of local caching of the IP addresses. I don't have dig utility and I have no idea how to check which host gives the result to getaddrinfo(). Still I'm sure that the addresses are not cached cause I'm trying to ping totally random URLs. Also given the slow GPRS response time it is not necessary to have the time measuring utility to see that ping takes 1-2 seconds or more to resolve IP before starting sending out packets. Furthermore ncsd, BIND or any dns servers do not run locally on the machine. I understand that you may not see that as proof, but that's what I have given the utility set available on my system.
I'd like to give some additional information concerning the internet connection operation.
Normal connection state
The rc script at system load runs another script as background process:
sh /etc/connect &
The connect script is as follows:
#!/bin/sh
echo First connect attempt > /etc/ppp/conn.info
while true
do
date >> /etc/ppp/conn.info
pppd call mts
echo Reconnecting... >> /etc/ppp/conn.info
done
The reason that I've made a loop here is simple: the connection persists for several hours and after that it always breaks. Unfortunately my implementation of pppd does not support the logfile option (so I can't see why is it broken). persist does not seem to work either so I've come to the connect script above. The pppd options are:
/dev/ttyM0 115200 crtscts
connect 'chat -f /etc/ppp/peers/mts.chat'
noauth
user mts
password mts
noipdefault
usepeerdns
defaultroute
ifconfig ppp0 gives:
ppp0 Link encap:Point-Point Protocol
inet addr:172.22.22.109 P-t-P:192.168.254.254 Mask:255.255.255.255
UP POINTOPOINT RUNNING NOARP MULTICAST MTU:1500 Metric:1
RX packets:34 errors:0 dropped:0 overruns:0 frame:0
TX packets:36 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:3
RX bytes:3130 (3.0 KiB) TX bytes:2250 (2.1 KiB)
And thats where it starts getting strange. Whenever I connect I'm getting different inet addr but P-t-p is always the same: 192.168.254.254. This is the same address that appears in default gateway entry, as given by netstat -rn:
Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
192.168.254.254 0.0.0.0 255.255.255.255 UH 0 0 0 ppp0
192.168.4.0 0.0.0.0 255.255.255.0 U 0 0 0 eth1
192.168.15.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
192.168.0.0 192.168.15.1 255.255.0.0 UG 0 0 0 eth0
0.0.0.0 192.168.254.254 0.0.0.0 UG 0 0 0 ppp0
route -Cevn is unavailable on my system, route gives the same info as above.
But I'm never able to ping the 192.168.254.254, not even when everything is working as intended: tcp connection, ping, DNS etc. Here is the result of traceroute:
traceroute to kernel.org (149.20.4.69), 30 hops max, 40 byte packets
1 172.16.4.210 (172.16.4.210) 528.765 ms 545.269 ms 616.67 ms
2 172.16.4.226 (172.16.4.226) 563.034 ms 526.176 ms 537.07 ms
3 10.250.85.161 (10.250.85.161) 572.805 ms 564.073 ms 556.766 ms
4 172.31.250.9 (172.31.250.9) 556.513 ms 563.383 ms 580.724 ms
5 172.31.250.10 (172.31.250.10) 518.15 ms 526.403 ms 537.574 ms
6 pub2.kernel.org (149.20.4.69) 538.058 ms 514.222 ms 538.575 ms
7 pub2.kernel.org (149.20.4.69) 537.531 ms 538.52 ms 537.556 ms
8 pub2.kernel.org (149.20.4.69) 568.695 ms 523.099 ms 570.983 ms
9 pub2.kernel.org (149.20.4.69) 526.511 ms 534.583 ms 537.994 ms
##### traceroute loops here - why?? #######
So, I can assume that 172.16.4.210 is peer's address. Such address is pingable in any case (see below). I have no idea why the structure of traceroute output is like this (packets come from internal network of ISP right to the destination, 'loop' at the destination address - it just should not be like this).
Also I would like to note that I can ping DNS server but traceroute does not go all the way up to it.
You may notice that there are eth0 and eth1 devices. They are irrelevant to the case. eth1 is not connected and eth0 is connected to lan without internet access.
Bad connection state
So, some time passes and the situation under question appears. I can't ping anything but DNS server (and peer, the address for which I get from traceroute result for the DNS) and cant communicate with remote host via tcp. DNS resolving is working
The network utilites give the same output as in normal state. I have the same unpingable peer (192.168.254.254 from ifconfig result), the routing table is the same:
# ifconfig ppp0
ppp0 Link encap:Point-Point Protocol
inet addr:172.22.22.109 P-t-P:192.168.254.254 Mask:255.255.255.255
UP POINTOPOINT RUNNING NOARP MULTICAST MTU:1500 Metric:1
RX packets:297 errors:0 dropped:0 overruns:0 frame:0
TX packets:424 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:3
RX bytes:33706 (32.9 KiB) TX bytes:27451 (26.8 KiB)
# route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.254.254 * 255.255.255.255 UH 0 0 0 ppp0
192.168.4.0 * 255.255.255.0 U 0 0 0 eth1
192.168.15.0 * 255.255.255.0 U 0 0 0 eth0
192.168.0.0 192.168.15.1 255.255.0.0 UG 0 0 0 eth0
default 192.168.254.254 0.0.0.0 UG 0 0 0 ppp0
Note that the original ppp connection (one which I used to provide the output from normal state) persisted. My /etc/connect script did not loop (there was no new record in a makeshift log the script makes).
Here goes the ping to DNS server:
# cat /etc/resolv.conf
#search moxa.com
nameserver 213.87.0.1
nameserver 213.87.1.1
# ping 213.87.0.1
PING 213.87.0.1 (213.87.0.1): 56 data bytes
64 bytes from 213.87.0.1: icmp_seq=0 ttl=59 time=559.8 ms
64 bytes from 213.87.0.1: icmp_seq=1 ttl=59 time=509.9 ms
64 bytes from 213.87.0.1: icmp_seq=2 ttl=59 time=559.8 ms
And traceroute:
# traceroute 213.87.0.1
traceroute to 213.87.0.1 (213.87.0.1), 30 hops max, 40 byte packets
1 172.16.4.210 (172.16.4.210) 542.449 ms 572.858 ms 595.681 ms
2 172.16.4.214 (172.16.4.214) 590.392 ms 565.887 ms 676.919 ms
3 * * *
4 217.8.237.62 (217.8.237.62) 603.1 ms 569.078 ms 553.723 ms
5 * * *
6 * * *
## and so on ###
*** lines may look like trouble but im getting the same traceroute for that DNS in normal situation
ping to 172.16.4.210 works fine as well.
Now to TCP. I've started a simple echo server on my PC and tried to connect via telnet to it (the actual ip address is not shown):
# telnet XXX.XXX.XXX.XXX 9060
Trying XXX.XXX.XXX.XXX(25635)...
Connected to XXX.XXX.XXX.XXX.
Escape character is '^]'.
aaabbbccc
Connection closed by foreign host.
So thats what happened here. Successfull connect() just like in my custom application is followed by Connection closed... when telnet called read(). The actual server did not receive any incoming connection. Why did 'connect()' return normally (it could not get the handshake response from the host!) is beyond my scope of knowledge.
Sure enough same telnet test works fine in normal state.
Note:
I did not publish this on serverfault cause of the embedded nature of my system. serverfault as far as I understand deals with more conventional systems (like x86s running 'normal' linux). I just hope that stackoverflow has more embedded experts who know such systems as my Moxa.
Q: How can I have DNS name resolving running while other protocols seem to be down?
A: Your local DNS resolver (bind is another possibility besides ncsd) might be caching the first response. dig will tell you where you are getting the response from:
[mpenning#Bucksnort ~]$ dig cisco.com
; <<>> DiG 9.6-ESV-R4 <<>> +all cisco.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 22106
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 2, ADDITIONAL: 0
;; QUESTION SECTION:
;cisco.com. IN A
;; ANSWER SECTION:
cisco.com. 86367 IN A 198.133.219.25
;; AUTHORITY SECTION:
cisco.com. 86367 IN NS ns2.cisco.com.
cisco.com. 86367 IN NS ns1.cisco.com.
;; Query time: 1 msec <----------------------- 1msec is usually cached
;; SERVER: 127.0.0.1#53(127.0.0.1) <--------------- Answered by localhost
;; WHEN: Wed Dec 7 04:41:21 2011
;; MSG SIZE rcvd: 79
[mpenning#Bucksnort ~]$
If you are getting a very quick (low milliseconds) answer from 127.0.0.1, then it's very likely that you're getting a locally cached answer from a prior query of the same DNS name (and it's quite common for people to use caching DNS resolvers on a ppp connection to reduce connection time, as well as achieving a small load reduction on the ppp link).
If you suspect a cached answer, do a dig on some other DNS name to see whether it can resolve too.
If random DNS names continue resolution and you still cannot make a TCP connection to a certain host, this is worthy of noting when you edit the question after this investigation.
If random DNS names don't resolve, then this is indicative of something like the loss of your default route, or the ppp connection going down.
Other diagnostic information
If you find yourself in either of the last situations I described, you need to do some IP and ppp-level debugs before this can be isolated further. As someone mentioned, tcpdump is quite valuable at this point, but it sounds like you don't have it available.
I assume you are not making a TCP connection to the same IP address of your DNS server. There are many possibilities at this point... If you can still resolve random DNS names, but TCP connections are failing, it is possible that the problem you are seeing is on the other side of the ppp connection, that the kernel routing cache (which holds a little TCP state information like MSS) is getting messed up, you have too much packet loss for tcp, or any number of things.
Let's assume your topology is like this:
10.1.1.2/30 10.1.1.1/30
[ppp0] [pppX]
uCLinux----------------------AccessServer---->[To the reset of the network]
When you initiate your ppp connection, take note of your IP address and the address of your default gateway:
ip link show ppp0 # display the link status of your ppp0 intf (is it up?)
ip addr show ppp0 # display the IP address of your ppp0 interface
ip route show # display your routing table
route -Cevn # display the kernel's routing cache
Similar results can be found if you don't have the iproute2 package as part of your distro (iproute2 provides the ip utility):
ifconfig ppp0 # display link status and addresses on ppp0
netstat -rn # display routing table
route -Cevn # display kernel routing table
For those with the iproute2 utilities (which is almost everybody these days), ifconfig has been deprecated and replaced by the ip commands; however, if you have an older 2.2 or 2.4-based system you may still need to use ifconfig.
Troubleshooting steps:
When you start having the problem, first check whether you can ping the address of pppX on your access server.
If you can not ping the ip address of pppX on the other side, then it is highly unlikely your DNS is getting resolved by anything other than a cached response on your uCLinux machine.
If you can ping pppX, then try to ping the ip address of your TCP peer and the IP address of the DNS (if it is not on localhost). Unless there is a firewall involved, you must be able to ping it successfully for any of this to work.
If you can ping the ip address of pppX but you cannot ping your TCP peer's ip address, check your routing table to see whether your default route is still pointing out ppp0
If your default route points through ppp0, check whether you can still ping the ip address of the default route.
If you can ping your default route and you can ping the remote host that you're trying to connect to, check the kernel's routing cache for the IP address of the remote TCP host.... look for anything odd or suspicious
If you can ping the remote TCP host (and you need to do about 200 pings to be sure... tcp is sensitive to significant packet loss & GPRS is notoriously lossy), try making a successful telnet <remote_host> <remote_port>. If both are successful, then it's time to start looking inside your software for clues.
If you still can't untangle what is happening, please include the output of the aforementioned commands when you come back... as well as how you're starting the ppp connection.
Pings should never be part of an end-user application(see note), and no program should rely on ping to function. At best ping might tell us that a part of the TCP/IP stack was running on the remote. See my argument here.
What the OP describes as a problem doesn't seem to be a problem. All network connections fail, the resolver may or may not use the network, and ping isn't really helpful. I would guess that the OP can check that the modem is connected or not, and if it isn't connect again.
edit: Pseudo code
do until success
try
connect "foobar.com"
try
write data
read response
catch
not success
endtry
catch error
'modem down - reconnect
not success
end try
loop
Note: the exception would be if you are writing a network monitoring application for a networking person.

Resources