* How to use ixp4xx_hss (or generic-hdlc?) @ 2008-11-20 17:42 Miguel Ángel Álvarez 2008-11-20 22:24 ` Francois Romieu 2008-11-21 23:09 ` Krzysztof Halasa 0 siblings, 2 replies; 8+ messages in thread From: Miguel Ángel Álvarez @ 2008-11-20 17:42 UTC (permalink / raw) To: netdev, khc Hi. Is there any kind of tutorials on using generic-hdlc interfaces? I just want to make a simple point-to-point connection between two devices using ixp4xx_hss. I would like the data to be packetized using hdlc. So... The questions are... - I suppose I should use sethdlc to configure the interface, but I am not sure about the configuration except that I should set "hdlc" protocol (I hope). - Then I should "open" the interface. I am trying with "ifconfig hdlc0 up", but I obtain an "ifconfig: SIOCSIFFLAGS: Function not implemented". As my previous use of net devices has been using ethernet or wifi devices in an "IP world", I am not quite sure if ifconfig should be used in this case. - Then I hope that I should open a raw (SOCK_RAW) PF_PACKET socket with protocol IPPROTO_RAW? I am not using IP, so this does not seem to be the correct protocol, but... - And the address to sendto the data? Should it be formed just using the name of the interface or it requires more data? Thanks. I know these should be really newbie questions, but I am finding difficult to know how to manage a "serial" device using a netdev interface. Miguel Ángel Álvarez ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: How to use ixp4xx_hss (or generic-hdlc?) 2008-11-20 17:42 How to use ixp4xx_hss (or generic-hdlc?) Miguel Ángel Álvarez @ 2008-11-20 22:24 ` Francois Romieu 2008-11-21 8:18 ` Miguel Ángel Álvarez 2008-11-21 23:09 ` Krzysztof Halasa 1 sibling, 1 reply; 8+ messages in thread From: Francois Romieu @ 2008-11-20 22:24 UTC (permalink / raw) To: Miguel Ángel Álvarez; +Cc: netdev, khc Miguel Ángel Álvarez <gotzoncabanes@gmail.com> : [...] > Is there any kind of tutorials on using generic-hdlc interfaces? Google + ixp4xx_hss + sethdlc -> first entry http://www.kernel.org/pub/linux/utils/net/hdlc/ The DSCC4 mini-HOWTO is rather old but it is imho a decent intro if you are a bit lost. -- Ueimor ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: How to use ixp4xx_hss (or generic-hdlc?) 2008-11-20 22:24 ` Francois Romieu @ 2008-11-21 8:18 ` Miguel Ángel Álvarez 2008-11-21 23:28 ` Krzysztof Halasa 0 siblings, 1 reply; 8+ messages in thread From: Miguel Ángel Álvarez @ 2008-11-21 8:18 UTC (permalink / raw) To: Francois Romieu; +Cc: netdev, khc Hi and thanks for the answer. On Thu, Nov 20, 2008 at 11:24 PM, Francois Romieu <romieu@fr.zoreil.com> wrote: > Miguel Ángel Álvarez <gotzoncabanes@gmail.com> : > [...] >> Is there any kind of tutorials on using generic-hdlc interfaces? > > Google + ixp4xx_hss + sethdlc -> first entry Ummm? Not for me at least. If I do that I only find my previous post and some information about goramo platform in polish (made by krzysztof. > > http://www.kernel.org/pub/linux/utils/net/hdlc/ Yes... I checked that in the beginning, and there is where I found the need to use sethdlc and the basic processes. (By the way... I do not have the problem in ifconfig-ing up the interface... I just were forgetting to so "sethdlc hdlc0 hdlc" previously). > > The DSCC4 mini-HOWTO is rather old but it is imho a decent intro > if you are a bit lost. > I also checked it, and I found it very illustrating. Good work of Frantisek (based on yours and Krzysztof's). I have also taken a look to the code of sethdlc to see how the socket to the interface was set. He made "sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_IP);" which I suppose does not care a lot because sethdlc only uses the socket to send ioctls, and not any data transfers. However, in my case, I need to send data in a non-IP world using the interface. So... Is this the way I should open the socket? Would this encapsulate my data in hdlc before sending it to the interface? if I open the socket using sock = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL)); I can send data into the interface, but it is just sent as raw data (which is logic). So... yes... I am a bit lost in this point. Thanks Miguel Ángel Álvarez ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: How to use ixp4xx_hss (or generic-hdlc?) 2008-11-21 8:18 ` Miguel Ángel Álvarez @ 2008-11-21 23:28 ` Krzysztof Halasa 2008-11-24 9:56 ` Miguel Ángel Álvarez 0 siblings, 1 reply; 8+ messages in thread From: Krzysztof Halasa @ 2008-11-21 23:28 UTC (permalink / raw) To: Miguel Ángel Álvarez; +Cc: Francois Romieu, netdev "Miguel Ángel Álvarez" <gotzoncabanes@gmail.com> writes: > I have also taken a look to the code of sethdlc to see how the socket > to the interface was set. He made "sock = socket(PF_INET, SOCK_DGRAM, > IPPROTO_IP);" which I suppose does not care a lot because sethdlc only > uses the socket to send ioctls, and not any data transfers. This is a bit different matter, though you may need it to get ifr_index. > However, in my case, I need to send data in a non-IP world using the > interface. So... Is this the way I should open the socket? Would this > encapsulate my data in hdlc before sending it to the interface? > > if I open the socket using sock = socket(PF_PACKET, SOCK_RAW, > htons(ETH_P_ALL)); I can send data into the interface, but it is just > sent as raw data (which is logic). It should be bit-stuffed and encapsulated in HDLC frames (flags etc), assuming a real HDLC device. You may need to prepend some headers, though. The basic idea is: int sock; struct ifreq ifr; struct sockaddr_ll addr; strcpy(ifr.ifr_name, "hdlc0"); if ((sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_IP)) < 0) error(); if (ioctl(sock, SIOCGIFINDEX, &ifr)) error(); close(sock); if ((sock = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL))) < 0) error(); memset(&addr, 0, sizeof(addr)); addr.sll_family = AF_PACKET; addr.sll_protocol = htons(ETH_P_ALL); addr.sll_ifindex = ifr.ifr_ifindex; then: sendto(sock, packet_data, packet_size, 0, &addr, sizeof(addr)) < 0) for RX: if (bind(sock, &addr, sizeof(addr)) < 0) error(); then: recvfrom(sock, buffer, max_packet_size, 0, &addr, &addr_len) -- Krzysztof Halasa ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: How to use ixp4xx_hss (or generic-hdlc?) 2008-11-21 23:28 ` Krzysztof Halasa @ 2008-11-24 9:56 ` Miguel Ángel Álvarez 2008-11-24 16:33 ` Krzysztof Halasa 0 siblings, 1 reply; 8+ messages in thread From: Miguel Ángel Álvarez @ 2008-11-24 9:56 UTC (permalink / raw) To: Krzysztof Halasa; +Cc: Francois Romieu, netdev Hi 2008/11/22 Krzysztof Halasa <khc@pm.waw.pl>: > "Miguel Ángel Álvarez" <gotzoncabanes@gmail.com> writes: > >> I have also taken a look to the code of sethdlc to see how the socket >> to the interface was set. He made "sock = socket(PF_INET, SOCK_DGRAM, >> IPPROTO_IP);" which I suppose does not care a lot because sethdlc only >> uses the socket to send ioctls, and not any data transfers. > > This is a bit different matter, though you may need it to get ifr_index. > Sure. You are right. >> However, in my case, I need to send data in a non-IP world using the >> interface. So... Is this the way I should open the socket? Would this >> encapsulate my data in hdlc before sending it to the interface? >> >> if I open the socket using sock = socket(PF_PACKET, SOCK_RAW, >> htons(ETH_P_ALL)); I can send data into the interface, but it is just >> sent as raw data (which is logic). > > It should be bit-stuffed and encapsulated in HDLC frames (flags etc), > assuming a real HDLC device. > > You may need to prepend some headers, though. > I am not sure of having understood you. The buffer I send using sendto should be just the payload and the generic-hdlc (or the hardware) encapsulates it in an hdlc frame, or should I prepare the whole frame? > The basic idea is: > > int sock; > struct ifreq ifr; > struct sockaddr_ll addr; > > strcpy(ifr.ifr_name, "hdlc0"); > if ((sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_IP)) < 0) > error(); > if (ioctl(sock, SIOCGIFINDEX, &ifr)) > error(); > close(sock); > > if ((sock = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL))) < 0) > error(); > > memset(&addr, 0, sizeof(addr)); > addr.sll_family = AF_PACKET; > addr.sll_protocol = htons(ETH_P_ALL); > addr.sll_ifindex = ifr.ifr_ifindex; > then: > sendto(sock, packet_data, packet_size, 0, &addr, sizeof(addr)) < 0) > > for RX: > if (bind(sock, &addr, sizeof(addr)) < 0) > error(); > then: > recvfrom(sock, buffer, max_packet_size, 0, &addr, &addr_len) I took a little different approach, using the same PF_PACKET socket to obtain the ifr_ifindex, but in any case using your method or "my" method, and activating the debugging in ixp4xx_hss, when I do a two byte (0x30 0x31) sendto, the traces in debug_pkt give me: 1970/01/01,00:00:47 (none) user.debug kernel: hdlc0: hss_hdlc_xmit(2) <7> 30<7>31<7> I cannot test the real hardware output in the lines at the moment, so I do not know if this is what I was supposed to obtain, or not (talking about the hdlc headers and trailers...). Thanks Miguel Ángel ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: How to use ixp4xx_hss (or generic-hdlc?) 2008-11-24 9:56 ` Miguel Ángel Álvarez @ 2008-11-24 16:33 ` Krzysztof Halasa 2008-11-25 7:24 ` Miguel Ángel Álvarez 0 siblings, 1 reply; 8+ messages in thread From: Krzysztof Halasa @ 2008-11-24 16:33 UTC (permalink / raw) To: Miguel Ángel Álvarez; +Cc: Francois Romieu, netdev "Miguel Ángel Álvarez" <gotzoncabanes@gmail.com> writes: > I am not sure of having understood you. The buffer I send using sendto > should be just the payload and the generic-hdlc (or the hardware) > encapsulates it in an hdlc frame, or should I prepare the whole > frame? You sendto() the payload, but what is a payload? With a normal HDLC hw driver, it (and the hardware) will generate the flag sequences, will do bit-(de)stuffing, will calculate and check the checksums, residual bits, aborts etc. You usually have to add 32-bit header: u8 address (broadcast, multicast, unicast) and control (such as unnumbered frame type), and u16 protocol number (IPv4, IPv6 etc, LCP/IPCP, Cisco keepalive etc). That's why it's called "raw HDLC", you're dealing with raw HDLC packets. > I took a little different approach, using the same PF_PACKET socket to > obtain the ifr_ifindex, but in any case using your method or "my" > method, and activating the debugging in ixp4xx_hss, when I do a two > byte (0x30 0x31) sendto, the traces in debug_pkt give me: > > 1970/01/01,00:00:47 (none) user.debug kernel: hdlc0: hss_hdlc_xmit(2) > <7> 30<7>31<7> It should do just that (those '<7>' are weird, though). -- Krzysztof Halasa ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: How to use ixp4xx_hss (or generic-hdlc?) 2008-11-24 16:33 ` Krzysztof Halasa @ 2008-11-25 7:24 ` Miguel Ángel Álvarez 0 siblings, 0 replies; 8+ messages in thread From: Miguel Ángel Álvarez @ 2008-11-25 7:24 UTC (permalink / raw) To: Krzysztof Halasa; +Cc: Francois Romieu, netdev Hi 2008/11/24 Krzysztof Halasa <khc@pm.waw.pl>: > "Miguel Ángel Álvarez" <gotzoncabanes@gmail.com> writes: > >> I am not sure of having understood you. The buffer I send using sendto >> should be just the payload and the generic-hdlc (or the hardware) >> encapsulates it in an hdlc frame, or should I prepare the whole >> frame? > > You sendto() the payload, but what is a payload? > > With a normal HDLC hw driver, it (and the hardware) will generate the > flag sequences, will do bit-(de)stuffing, will calculate and check the > checksums, residual bits, aborts etc. > > You usually have to add 32-bit header: u8 address (broadcast, > multicast, unicast) and control (such as unnumbered frame type), and > u16 protocol number (IPv4, IPv6 etc, LCP/IPCP, Cisco keepalive etc). > That's why it's called "raw HDLC", you're dealing with raw HDLC > packets. > You are right... I was being quite simplistic. >> I took a little different approach, using the same PF_PACKET socket to >> obtain the ifr_ifindex, but in any case using your method or "my" >> method, and activating the debugging in ixp4xx_hss, when I do a two >> byte (0x30 0x31) sendto, the traces in debug_pkt give me: >> >> 1970/01/01,00:00:47 (none) user.debug kernel: hdlc0: hss_hdlc_xmit(2) >> <7> 30<7>31<7> > > It should do just that (those '<7>' are weird, though). Yes... I do not know where they can from, but I am 100% sure it is only representation of the printk. Thanks a lot. Things are much clear now. Miguel Ángel Álvarez ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: How to use ixp4xx_hss (or generic-hdlc?) 2008-11-20 17:42 How to use ixp4xx_hss (or generic-hdlc?) Miguel Ángel Álvarez 2008-11-20 22:24 ` Francois Romieu @ 2008-11-21 23:09 ` Krzysztof Halasa 1 sibling, 0 replies; 8+ messages in thread From: Krzysztof Halasa @ 2008-11-21 23:09 UTC (permalink / raw) To: Miguel Ángel Álvarez; +Cc: netdev "Miguel Ángel Álvarez" <gotzoncabanes@gmail.com> writes: > Is there any kind of tutorials on using generic-hdlc interfaces? Not much, Documentation/networking/generic-hdlc.txt. > I > just want to make a simple point-to-point connection between two > devices using ixp4xx_hss. I would like the data to be packetized using > hdlc. > - I suppose I should use sethdlc to configure the interface, but I am > not sure about the configuration except that I should set "hdlc" > protocol (I hope). Sure. > - Then I should "open" the interface. I am trying with "ifconfig hdlc0 > up", but I obtain an "ifconfig: SIOCSIFFLAGS: Function not > implemented". As my previous use of net devices has been using > ethernet or wifi devices in an "IP world", I am not quite sure if > ifconfig should be used in this case. modprobe driver and maybe hdlc_raw sethdlc hdlc0 hdlc ifconfig hdlc0 up should work fine. > - Then I hope that I should open a raw (SOCK_RAW) PF_PACKET socket > with protocol IPPROTO_RAW? I am not using IP, so this does not seem to > be the correct protocol, but... Seems entirely correct. > - And the address to sendto the data? Should it be formed just using > the name of the interface or it requires more data? No, all data is sent to the other end :-) > Thanks. I know these should be really newbie questions, but I am > finding difficult to know how to manage a "serial" device using a > netdev interface. Actually it's a bit different than normal async serial ports - HDLC means packets. -- Krzysztof Halasa ^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2008-11-25 7:24 UTC | newest] Thread overview: 8+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2008-11-20 17:42 How to use ixp4xx_hss (or generic-hdlc?) Miguel Ángel Álvarez 2008-11-20 22:24 ` Francois Romieu 2008-11-21 8:18 ` Miguel Ángel Álvarez 2008-11-21 23:28 ` Krzysztof Halasa 2008-11-24 9:56 ` Miguel Ángel Álvarez 2008-11-24 16:33 ` Krzysztof Halasa 2008-11-25 7:24 ` Miguel Ángel Álvarez 2008-11-21 23:09 ` Krzysztof Halasa
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox