kernelnewbies.kernelnewbies.org archive mirror
 help / color / mirror / Atom feed
* Adding new protocol to linux.
@ 2016-03-26  2:00 Daniel.
  2016-03-26 11:04 ` Rami Rosen
  2016-03-26 19:59 ` Valdis.Kletnieks at vt.edu
  0 siblings, 2 replies; 5+ messages in thread
From: Daniel. @ 2016-03-26  2:00 UTC (permalink / raw)
  To: kernelnewbies

Hi everybody,

I'm planing to write a socket API for Nordic's nRF24L01+ and I was
digging on socket code and find all supported protocols at
include/linux/socket.h with all that #define AF_x y. So my questions
are:

1) Is it possible to write a new protocol for linux with an out of
tree module without modifing socket.h file?
2) Could netlink socket be used to solve this? .. and
3) I saw that there is net_device_ops and proto_ops. How they are tied together?

Thanks in advance and
Best regards,

-- 
"Do or do not. There is no try"
  Yoda Master

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

* Adding new protocol to linux.
  2016-03-26  2:00 Adding new protocol to linux Daniel.
@ 2016-03-26 11:04 ` Rami Rosen
       [not found]   ` <CAF3SDA5kn7_Pnx0=XpeQOB-D2UCeYZEnzPpcE=25U30ob9KSHQ@mail.gmail.com>
  2016-03-26 19:59 ` Valdis.Kletnieks at vt.edu
  1 sibling, 1 reply; 5+ messages in thread
From: Rami Rosen @ 2016-03-26 11:04 UTC (permalink / raw)
  To: kernelnewbies

Hi Daniel,

Following are answers for several of your questions:
Adding a protocol in Linux is done first by defining a protocol, and
then registering it with the proto_register() method:
http://lxr.free-electrons.com/source/net/core/sock.c#L2815
For that you need to define a proto object; for TCPv4 it is done thus,
for example:
http://lxr.free-electrons.com/source/net/ipv4/tcp_ipv4.c#L2315

Defining a protocol is not enough, you should also register a protocol
handler for this protocol.
Defining a protocol handler is done first by
defining a packet_type object
of this protocol and then defining a callback for this packet_type.
So for example, for IPv4, a packet_type object called ip_packet_type is
defined in http://lxr.free-electrons.com/source/net/ipv4/af_inet.c#L1677

The protocol handler for this packet type is ip_rcv():
http://lxr.free-electrons.com/source/net/ipv4/ip_input.c#L378

This protocol is registered with dev_add_pack():
http://lxr.free-electrons.com/source/net/core/dev.c#L397

So, for example, for IPv4 it is done in inet_init():
http://lxr.free-electrons.com/source/net/ipv4/af_inet.c#L1791

Apart from the protocol handler, a unique Ethernet type should be
defined for this protocol; for IPv4 we have  0x0800 (ETH_P_IP)
http://lxr.free-electrons.com/source/include/uapi/linux/if_ether.h#L46
and for the ARP protocol we have 0x0806 (ETH_P_ARP), and so on.

The Ethernet type in the Ethernet header represents the protocol
assigned to this packet.

The net_device_ops structure is not related, it merely represents the
interface of the of the kernel representation of network device (a
net_device object)  to userspace, for userspace operations like
setting the MTU, setting the MAC address, bringing the device up and
down, putting the device in promiscuous mode, and more.

Hope this helps!

Regards,
Rami Rosen
http://ramirose.wix.com/ramirosen


On 26 March 2016 at 05:00, Daniel. <danielhilst@gmail.com> wrote:
> Hi everybody,
>
> I'm planing to write a socket API for Nordic's nRF24L01+ and I was
> digging on socket code and find all supported protocols at
> include/linux/socket.h with all that #define AF_x y. So my questions
> are:
>
> 1) Is it possible to write a new protocol for linux with an out of
> tree module without modifing socket.h file?
> 2) Could netlink socket be used to solve this? .. and
> 3) I saw that there is net_device_ops and proto_ops. How they are tied together?
>
> Thanks in advance and
> Best regards,
>
> --
> "Do or do not. There is no try"
>   Yoda Master
>
> _______________________________________________
> Kernelnewbies mailing list
> Kernelnewbies at kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

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

* Adding new protocol to linux.
  2016-03-26  2:00 Adding new protocol to linux Daniel.
  2016-03-26 11:04 ` Rami Rosen
@ 2016-03-26 19:59 ` Valdis.Kletnieks at vt.edu
  2016-03-26 23:49   ` Res: " Daniel
  1 sibling, 1 reply; 5+ messages in thread
From: Valdis.Kletnieks at vt.edu @ 2016-03-26 19:59 UTC (permalink / raw)
  To: kernelnewbies

On Fri, 25 Mar 2016 23:00:48 -0300, "Daniel." said:
> Hi everybody,
>
> I'm planing to write a socket API for Nordic's nRF24L01+ and I was
> digging on socket code and find all supported protocols at
> include/linux/socket.h with all that #define AF_x y. So my questions
> are:
>
> 1) Is it possible to write a new protocol for linux with an out of
> tree module without modifing socket.h file?

Rami Rosen gave a good outline of what's needed.  But the *first* question
you should ask is why a hardware device needs its own socket API rather than
re-using an existing one.  Basically, if it's an intelligent enough device
or SOC, you should be able to get it to talk at least UDP or something. And
if it's not that smart, maybe you shouldn't be trying to use sockets to talk to
it.

So what are the reasons you're doing a new socket API instead of using the
existing stuff?
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 848 bytes
Desc: not available
Url : http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20160326/01ac9324/attachment.bin 

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

* Adding new protocol to linux.
       [not found]   ` <CAF3SDA5kn7_Pnx0=XpeQOB-D2UCeYZEnzPpcE=25U30ob9KSHQ@mail.gmail.com>
@ 2016-03-26 23:30     ` Daniel
  0 siblings, 0 replies; 5+ messages in thread
From: Daniel @ 2016-03-26 23:30 UTC (permalink / raw)
  To: kernelnewbies

Thanks Rami, it helps a lot. I'm using SocketCAN as reference for doing this, and I see AF_CAN at socket.h. I saw that protocol family create is called by __sock_create(). Also found that proto_ops bind is used (in the example of the CAN) to find the interface where the communication realy happens.. I am wondering if is possible to achieve my goal with and only with out of tree module. I'm planing to get this merged at main tree anyway, but first I would like to keep it out ou tree until is ready...
Cheers,?

2016-03-26 8:04 GMT-03:00 Rami Rosen <roszenrami@gmail.com>:
> Hi Daniel,
>
> Following are answers for several of your questions:
> Adding a protocol in Linux is done first by defining a protocol, and
> then registering it with the proto_register() method:
> http://lxr.free-electrons.com/source/net/core/sock.c#L2815
> For that you need to define a proto object; for TCPv4 it is done thus,
> for example:
> http://lxr.free-electrons.com/source/net/ipv4/tcp_ipv4.c#L2315
>
> Defining a protocol is not enough, you should also register a protocol
> handler for this protocol.
> Defining a protocol handler is done first by
> defining a packet_type object
> of this protocol and then defining a callback for this packet_type.
> So for example, for IPv4, a packet_type object called ip_packet_type is
> defined in http://lxr.free-electrons.com/source/net/ipv4/af_inet.c#L1677
>
> The protocol handler for this packet type is ip_rcv():
> http://lxr.free-electrons.com/source/net/ipv4/ip_input.c#L378
>
> This protocol is registered with dev_add_pack():
> http://lxr.free-electrons.com/source/net/core/dev.c#L397
>
> So, for example, for IPv4 it is done in inet_init():
> http://lxr.free-electrons.com/source/net/ipv4/af_inet.c#L1791
>
> Apart from the protocol handler, a unique Ethernet type should be
> defined for this protocol; for IPv4 we have 0x0800 (ETH_P_IP)
> http://lxr.free-electrons.com/source/include/uapi/linux/if_ether.h#L46
> and for the ARP protocol we have 0x0806 (ETH_P_ARP), and so on.
>
> The Ethernet type in the Ethernet header represents the protocol
> assigned to this packet.
>
> The net_device_ops structure is not related, it merely represents the
> interface of the of the kernel representation of network device (a
> net_device object) to userspace, for userspace operations like
> setting the MTU, setting the MAC address, bringing the device up and
> down, putting the device in promiscuous mode, and more.
>
> Hope this helps!
>
> Regards,
> Rami Rosen
> http://ramirose.wix.com/ramirosen
>
>
> On 26 March 2016 at 05:00, Daniel. <danielhilst@gmail.com> wrote:
>> Hi everybody,
>>
>> I'm planing to write a socket API for Nordic's nRF24L01+ and I was
>> digging on socket code and find all supported protocols at
>> include/linux/socket.h with all that #define AF_x y. So my questions
>> are:
>>
>> 1) Is it possible to write a new protocol for linux with an out of
>> tree module without modifing socket.h file?
>> 2) Could netlink socket be used to solve this? .. and
>> 3) I saw that there is net_device_ops and proto_ops. How they are tied together?
>>
>> Thanks in advance and
>> Best regards,
>>
>> --
>> "Do or do not. There is no try"
>> Yoda Master
>>
>> _______________________________________________
>> Kernelnewbies mailing list
>> Kernelnewbies at kernelnewbies.org
>> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies



-- 
"Do or do not. There is no try"
Yoda Master

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

* Res: Adding new protocol to linux.
  2016-03-26 19:59 ` Valdis.Kletnieks at vt.edu
@ 2016-03-26 23:49   ` Daniel
  0 siblings, 0 replies; 5+ messages in thread
From: Daniel @ 2016-03-26 23:49 UTC (permalink / raw)
  To: kernelnewbies



Enviado?do?meu?smartphone?BlackBerry?10.
? Mensagem original ?
De: Valdis.Kletnieks at vt.edu
Enviada: s?bado, 26 de mar?o de 2016 16:59
Para: Daniel.
Cc: kernelnewbies
Assunto: Re: Adding new protocol to linux.

On Fri, 25 Mar 2016 23:00:48 -0300, "Daniel." said:
> Hi everybody,
>
> I'm planing to write a socket API for Nordic's nRF24L01+ and I was
> digging on socket code and find all supported protocols at
> include/linux/socket.h with all that #define AF_x y. So my questions
> are:
>
> 1) Is it possible to write a new protocol for linux with an out of
> tree module without modifing socket.h file?

Rami Rosen gave a good outline of what's needed. But the *first* question
you should ask is why a hardware device needs its own socket API rather than
re-using an existing one. Basically, if it's an intelligent enough device
or SOC, you should be able to get it to talk at least UDP or something. And
if it's not that smart, maybe you shouldn't be trying to use sockets to talk to
it.

So what are the reasons you're doing a new socket API instead of using the
existing stuff?

Hi Valdis, thanks for the answer. The big problem here is that this piece of hardware has really tiny payloads, only 32 bytes long and is not of standard type. Also I want to add some routing bits, the final goal is to have something like xbee but GPL and cheaper. I thought to use IP at first but the hw payloads are too small, so I think in writing a new protocol module and then I found the socket.h file.

Thanks for your reply
Cheers

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

end of thread, other threads:[~2016-03-26 23:49 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-03-26  2:00 Adding new protocol to linux Daniel.
2016-03-26 11:04 ` Rami Rosen
     [not found]   ` <CAF3SDA5kn7_Pnx0=XpeQOB-D2UCeYZEnzPpcE=25U30ob9KSHQ@mail.gmail.com>
2016-03-26 23:30     ` Daniel
2016-03-26 19:59 ` Valdis.Kletnieks at vt.edu
2016-03-26 23:49   ` Res: " Daniel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).