All of lore.kernel.org
 help / color / mirror / Atom feed
* Sample code for 6Lo tx/rx
@ 2015-01-28  9:57 Rohit Kulkarni
  2015-01-28 11:09 ` Rohit Kulkarni
  0 siblings, 1 reply; 6+ messages in thread
From: Rohit Kulkarni @ 2015-01-28  9:57 UTC (permalink / raw)
  To: linux-wpan

Hi,

I was wondering if there is any example code that can tx/rx over a
6LoWPAN "node" interface. I've looked through the Unstrung code for
some examples but it uses ICMP all over. I'd really appreciate if
someone had any code samples for sending udp data over wpan. I tried
creating a SOCK_DGRAM socket over AF_IEEE802154 and got the "Protocol
not supported" error. Creating a SOCK_RAW worked but my life would be
much easier if I could start using DGRAMs :-) (One of the earlier
emails on the list mentioned DGRAMs over 6LoWPAN!).

Also, I've never used RAW sockets before, so any help with RAW sockets
over wpan (if DGRAM is not really an option) will also be a huge help!

Thanks!
-Rohit

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Sample code for 6Lo tx/rx
  2015-01-28  9:57 Sample code for 6Lo tx/rx Rohit Kulkarni
@ 2015-01-28 11:09 ` Rohit Kulkarni
  2015-01-28 11:16   ` Rohit Kulkarni
  2015-01-28 21:04   ` Alexander Aring
  0 siblings, 2 replies; 6+ messages in thread
From: Rohit Kulkarni @ 2015-01-28 11:09 UTC (permalink / raw)
  To: linux-wpan

Hi,

I was wondering if there is any example code that can tx/rx over a
6LoWPAN "node" interface. I've looked through the Unstrung code for
some examples but it uses ICMP all over. I'd really appreciate if
someone had any code samples for sending udp data over wpan. I tried
creating a SOCK_DGRAM socket over AF_IEEE802154 and got the "Protocol
not supported" error. Creating a SOCK_RAW worked but my life would be
much easier if I could start using DGRAMs :-) (One of the earlier
emails on the list mentioned DGRAMs over 6LoWPAN!).

Also, I've never used RAW sockets before, so any help with RAW sockets
over wpan (if DGRAM is not really an option) will also be a huge help!

Thanks!
-Rohit

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Sample code for 6Lo tx/rx
  2015-01-28 11:09 ` Rohit Kulkarni
@ 2015-01-28 11:16   ` Rohit Kulkarni
  2015-01-28 14:03     ` Rohit Kulkarni
  2015-01-28 21:04   ` Alexander Aring
  1 sibling, 1 reply; 6+ messages in thread
From: Rohit Kulkarni @ 2015-01-28 11:16 UTC (permalink / raw)
  To: linux-wpan

Hi,

I'm sorry for re-posting the same query. Gmail was acting up and said
the earlier one could not be delivered!

-Rohit

On Wed, Jan 28, 2015 at 4:39 PM, Rohit Kulkarni <rmkulkar@gmail.com> wrote:
> Hi,
>
> I was wondering if there is any example code that can tx/rx over a
> 6LoWPAN "node" interface. I've looked through the Unstrung code for
> some examples but it uses ICMP all over. I'd really appreciate if
> someone had any code samples for sending udp data over wpan. I tried
> creating a SOCK_DGRAM socket over AF_IEEE802154 and got the "Protocol
> not supported" error. Creating a SOCK_RAW worked but my life would be
> much easier if I could start using DGRAMs :-) (One of the earlier
> emails on the list mentioned DGRAMs over 6LoWPAN!).
>
> Also, I've never used RAW sockets before, so any help with RAW sockets
> over wpan (if DGRAM is not really an option) will also be a huge help!
>
> Thanks!
> -Rohit

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Sample code for 6Lo tx/rx
  2015-01-28 11:16   ` Rohit Kulkarni
@ 2015-01-28 14:03     ` Rohit Kulkarni
  0 siblings, 0 replies; 6+ messages in thread
From: Rohit Kulkarni @ 2015-01-28 14:03 UTC (permalink / raw)
  To: linux-wpan

Hi,

I had made some embarrasing blunders to get the "Protocol not
supported" error!! :-)

I finally got the at86rf212 module to tx data. Here's the code that
worked, in case someone else is also looking for an example. Also, can
any of you just glance through it and let me know if something's wrong
with it?

Thanks!
Rohit

#include <sys/types.h>
#include <sys/socket.h>
#include <ieee802154.h>

#include <strings.h>    /* bzero() */
#include <unistd.h>     /* sleep() */

int main()
{
        struct sockaddr_ieee802154 host_addr;
        struct sockaddr_ieee802154 dest_addr;

        /* Create a 802.15.4 socket */
        int sock = socket(AF_IEEE802154, SOCK_DGRAM, 0);
        if(sock < 0)
        {
                perror("socket");
                return -1;
        }

        /* Fill in the host_addr object */
        bzero(&host_addr, sizeof(host_addr));

        host_addr.family         = AF_IEEE802154;
        host_addr.addr.addr_type = IEEE802154_ADDR_SHORT;
        host_addr.addr.pan_id    = 0xdead;
        host_addr.addr.short_addr= 0xbeef;

        if(bind(sock, (struct sockaddr *)&host_addr, sizeof(host_addr)) < 0)
        {
                perror("bind");
                return -1;
        }

        /* Fill in the dest_addr object */
        bzero(&dest_addr, sizeof(dest_addr));

        dest_addr.family    = AF_IEEE802154;
        dest_addr.addr.addr_type = IEEE802154_ADDR_SHORT;
        dest_addr.addr.pan_id    = 0xdead;
        dest_addr.addr.short_addr= 0xbeee;

        while(1)
        {
                if(sendto(sock, "Hello World", 12, 0, (struct sockaddr
*)&dest_addr, sizeof(dest_addr)) < 0)
                {
                        perror("sendto");
                        close(sock);
                        return -1;
                }

                sleep(2);
        }

        close(sock);
        return 0;
}

On Wed, Jan 28, 2015 at 4:46 PM, Rohit Kulkarni <rmkulkar@gmail.com> wrote:
> Hi,
>
> I'm sorry for re-posting the same query. Gmail was acting up and said
> the earlier one could not be delivered!
>
> -Rohit
>
> On Wed, Jan 28, 2015 at 4:39 PM, Rohit Kulkarni <rmkulkar@gmail.com> wrote:
>> Hi,
>>
>> I was wondering if there is any example code that can tx/rx over a
>> 6LoWPAN "node" interface. I've looked through the Unstrung code for
>> some examples but it uses ICMP all over. I'd really appreciate if
>> someone had any code samples for sending udp data over wpan. I tried
>> creating a SOCK_DGRAM socket over AF_IEEE802154 and got the "Protocol
>> not supported" error. Creating a SOCK_RAW worked but my life would be
>> much easier if I could start using DGRAMs :-) (One of the earlier
>> emails on the list mentioned DGRAMs over 6LoWPAN!).
>>
>> Also, I've never used RAW sockets before, so any help with RAW sockets
>> over wpan (if DGRAM is not really an option) will also be a huge help!
>>
>> Thanks!
>> -Rohit

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Sample code for 6Lo tx/rx
  2015-01-28 11:09 ` Rohit Kulkarni
  2015-01-28 11:16   ` Rohit Kulkarni
@ 2015-01-28 21:04   ` Alexander Aring
  2015-01-29  7:32     ` Rohit Kulkarni
  1 sibling, 1 reply; 6+ messages in thread
From: Alexander Aring @ 2015-01-28 21:04 UTC (permalink / raw)
  To: Rohit Kulkarni; +Cc: linux-wpan

Hi,

On Wed, Jan 28, 2015 at 04:39:48PM +0530, Rohit Kulkarni wrote:
> Hi,
> 
> I was wondering if there is any example code that can tx/rx over a
> 6LoWPAN "node" interface. I've looked through the Unstrung code for
> some examples but it uses ICMP all over. I'd really appreciate if
> someone had any code samples for sending udp data over wpan. I tried
> creating a SOCK_DGRAM socket over AF_IEEE802154 and got the "Protocol
> not supported" error. Creating a SOCK_RAW worked but my life would be
> much easier if I could start using DGRAMs :-) (One of the earlier
> emails on the list mentioned DGRAMs over 6LoWPAN!).
> 
> Also, I've never used RAW sockets before, so any help with RAW sockets
> over wpan (if DGRAM is not really an option) will also be a huge help!
> 

we need to clarify what exactly you want to do.

wpan interface:

Over this interface you can send IEEE 802.15.4 frames.

802.15.4 DGRAM sockets:
When creating a 802.15.4 DGRAM socket this will be dataframes only.

802.15.4 RAW sockets:
You can send whatever you want, you build the frame inside userspace
(except the FCS).


lowpan interface:

There should only create IPv6 connection on it, all others sockets types
will be dropped. Internal mechanism will translate IPv6 to 6LoWPAN and
vice versa.

For DGRAM, STREAM, RAW IPv6 socket types it's just the same like for
others link-types like ethernet.

Important note here: you can't create 802.15.4 sockets for a lowpan interface.



Now to your question if there exists examples:

Yes, there was some examples in the old lowpan-tools names "izchat" [0], but
this is an example for DGRAM sockets only.

Maybe we could add also some example like this in wpan-tools (we need to
reprogramm it, lowpan-tools ist GPLv2 and the new wpan-tools are under
the same license like "iw" which isn't GPL).

Possible idea would be to add example program like izchat with some switch to
use DGRAM or RAW 802.15.4 socket communication.

- Alex

[0] https://github.com/linux-wpan/lowpan-tools/blob/master/src/izchat.c

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Sample code for 6Lo tx/rx
  2015-01-28 21:04   ` Alexander Aring
@ 2015-01-29  7:32     ` Rohit Kulkarni
  0 siblings, 0 replies; 6+ messages in thread
From: Rohit Kulkarni @ 2015-01-29  7:32 UTC (permalink / raw)
  To: Alexander Aring; +Cc: linux-wpan

Hi,

So, if I create a regular IPV6 DGRAM socket, it'll use the lowpan
interface as long as I bind it to the lowpan's IPV6 address? Or do I
not even need to bind() and the kernel will choose the lowpan
interface depending on the destination IP? Please correct me if I'm
wrong. I'm working on a couple of different things - one will need
6lowpan and the other can work with just 802.15.4.

I looked at the izchat example and understood most of it. The one
thing I don't understand is why the code calls connect() on the DGRAM
socket. Is it in some ways necessary for all 802.15.4 DGRAM sockets?
Or is it just for the convenience of using send() v/s sendto()?

Thanks a lot!

-Rohit

On Thu, Jan 29, 2015 at 2:34 AM, Alexander Aring <alex.aring@gmail.com> wrote:
> Hi,
>
> On Wed, Jan 28, 2015 at 04:39:48PM +0530, Rohit Kulkarni wrote:
>> Hi,
>>
>> I was wondering if there is any example code that can tx/rx over a
>> 6LoWPAN "node" interface. I've looked through the Unstrung code for
>> some examples but it uses ICMP all over. I'd really appreciate if
>> someone had any code samples for sending udp data over wpan. I tried
>> creating a SOCK_DGRAM socket over AF_IEEE802154 and got the "Protocol
>> not supported" error. Creating a SOCK_RAW worked but my life would be
>> much easier if I could start using DGRAMs :-) (One of the earlier
>> emails on the list mentioned DGRAMs over 6LoWPAN!).
>>
>> Also, I've never used RAW sockets before, so any help with RAW sockets
>> over wpan (if DGRAM is not really an option) will also be a huge help!
>>
>
> we need to clarify what exactly you want to do.
>
> wpan interface:
>
> Over this interface you can send IEEE 802.15.4 frames.
>
> 802.15.4 DGRAM sockets:
> When creating a 802.15.4 DGRAM socket this will be dataframes only.
>
> 802.15.4 RAW sockets:
> You can send whatever you want, you build the frame inside userspace
> (except the FCS).
>
>
> lowpan interface:
>
> There should only create IPv6 connection on it, all others sockets types
> will be dropped. Internal mechanism will translate IPv6 to 6LoWPAN and
> vice versa.
>
> For DGRAM, STREAM, RAW IPv6 socket types it's just the same like for
> others link-types like ethernet.
>
> Important note here: you can't create 802.15.4 sockets for a lowpan interface.
>
>
>
> Now to your question if there exists examples:
>
> Yes, there was some examples in the old lowpan-tools names "izchat" [0], but
> this is an example for DGRAM sockets only.
>
> Maybe we could add also some example like this in wpan-tools (we need to
> reprogramm it, lowpan-tools ist GPLv2 and the new wpan-tools are under
> the same license like "iw" which isn't GPL).
>
> Possible idea would be to add example program like izchat with some switch to
> use DGRAM or RAW 802.15.4 socket communication.
>
> - Alex
>
> [0] https://github.com/linux-wpan/lowpan-tools/blob/master/src/izchat.c

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2015-01-29  7:32 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-01-28  9:57 Sample code for 6Lo tx/rx Rohit Kulkarni
2015-01-28 11:09 ` Rohit Kulkarni
2015-01-28 11:16   ` Rohit Kulkarni
2015-01-28 14:03     ` Rohit Kulkarni
2015-01-28 21:04   ` Alexander Aring
2015-01-29  7:32     ` Rohit Kulkarni

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.