From: Francesco Valla <valla.francesco@gmail.com>
To: Vincent Mailhol <vincent.mailhol@gmail.com>
Cc: Oliver Hartkopp <socketcan@hartkopp.net>,
Marc Kleine-Budde <mkl@pengutronix.de>,
linux-can@vger.kernel.org, netdev@vger.kernel.org,
linux-kernel@vger.kernel.org, Simon Horman <horms@kernel.org>,
Bagas Sanjaya <bagasdotme@gmail.com>,
fabio@redaril.me
Subject: Re: [PATCH v2 1/1] Documentation: networking: document ISO 15765-2:2016
Date: Tue, 16 Apr 2024 18:27:10 +0200 [thread overview]
Message-ID: <Zh6m3jkRovDutKnZ@fedora> (raw)
In-Reply-To: <CAMZ6RqKLaYb+8EaeoFMHofcaBT5G2-qdqSb4do73xrgMvWMZaA@mail.gmail.com>
Hi Vincent,
thank you for the review!
I'll omit from this reply the issue about the standard to be referenced
and the CAN-CC naming (discussed in another thread also with Oliver).
About the typos and formatting observations: rst is not my native
language (I'm more on the Markdown side), I'll apply all the corrections
you suggested. Thank you.
Some other considerations follow.
On Sat, Apr 13, 2024 at 10:11:55PM +0900, Vincent Mailhol wrote:
> Hi Francesco,
>
> Thank you for the ISO-TP documentation.
>
> I left a few comments, but overall, good work. Also, I did not double
> check each individual option one by one.
(...)
> > +
> > +- physical addressing is implemented by two node-specific addresses (CAN
> > + identifiers) and is used in 1-to-1 communication
> > +- functional addressing is implemented by one node-specific address (CAN
> > + identifier) and is used in 1-to-N communication
> > +
> > +In a so-called "normal" addressing scenario, both these addresses are
> > +represented by a 29-bit CAN ID. However, in order to support larger networks,
> > +an "extended" addressing scheme can be adopted: in this case, the first byte of
> > +the data payload is used as an additional component of the address (both for
> > +the physical and functional cases); two different CAN IDs are still required.
>
> There is more than that.
>
> - The normal addressing can also use the non-extended 11 bits CAN ID.
> - In addition to the normal and extended addressing mode, there
> is a third mode: the mixed addressing.
>
> Ref:
>
> - ISO 15765:2024 §10.3.1 "Addressing formats"
> - https://www.embedded-communication.com/en/misc/iso-tp-addressing/
>
You are right. I'll drop the reference to "29-bit" and add the mixed
addressing (I did not know it, I'll have to investigate a bit - I
personally always used the normal one).
(...)
>
> > +Unlike the CAN_RAW socket API, only the data payload shall be specified in all
> > +these calls, as the CAN header is automatically filled by the ISO-TP stack
> > +using information supplied during socket creation. In the same way, the stack
>
> This is making a shortcut. There are the raw CAN payload and the
> ISO-TP payload. In this paragraph it is not clear that "data payload"
> is referring to the ISO-TP payload.
>
> Also, what is the meaning of "the CAN header". Here, I think you mean
> CAN ID plus some of the few first byte of the CAN payload.
>
> I suggest that you use more precise vocabulary from the standard:
>
> - Address information
> - Protocol Information
> - Data field
>
> Something like:
>
> only the ISO-TP data field (the actual payload) is sent. The
> address information and the protocol information is
> automatically filled by the ISO-TP stack...
>
Indeed it is a shortcut. Your suggestion to adhere more to the standard
is welcome, I'd rephrase as:
Unlike the CAN_RAW socket API, only the ISO-TP data field (the actual payload)
is sent and received by the userspace application using these calls. The address
information and the protocol information are automatically filled by the ISO-TP
stack using the configuration supplied during socket creation. In the same way,
the stack will use the transport mechanism when required (i.e., when the size
of the data payload exceeds the MTU of the underlying CAN bus).
(...)
> > +Examples
> > +========
> > +
> > +Basic node example
> > +------------------
> > +
> > +Following example implements a node using "normal" physical addressing, with
> > +RX ID equal to 0x18DAF142 and a TX ID equal to 0x18DA42F1. All options are left
> > +to their default.
> > +
> > +.. code-block:: C
> > +
> > + int s;
> > + struct sockaddr_can addr;
>
> Here, I would suggest the C99 designated field initialization:
>
> struct sockaddr_can addr = {
> .can_family = AF_CAN;
> .can_ifindex = if_nametoindex("can0");
> .tp.tx_id = 0x18DA42F1 | CAN_EFF_FLAG;
> .tp.rx_id = 0x18DAF142 | CAN_EFF_FLAG;
> };
>
> Well, this is just a suggestion, feel free to reject it if you do not like it.
>
Not a fan of C99 designated field initialization inside functions, TBH.
Moreover, these parameters are typically specified through either the
command line or some configuration file. I'll keep my version.
> > + int ret;
> > +
> > + s = socket(PF_CAN, SOCK_DGRAM, CAN_ISOTP);
> > + if (s < 0)
> > + exit(1);
> > +
> > + addr.can_family = AF_CAN;
> > + addr.can_ifindex = if_nametoindex("can0");
>
> if_nametoindex() may fail. Because you are doing error handling in
> this example, do it also here:
>
> if (!addr.can_ifindex)
> err("if_nametoindex()");
>
> > + addr.tp.tx_id = (0x18DA42F1 | CAN_EFF_FLAG);
> > + addr.tp.rx_id = (0x18DAF142 | CAN_EFF_FLAG);
>
> Nitpick: the bracket are not needed here:
>
> addr.tp.tx_id = 0x18DA42F1 | CAN_EFF_FLAG;
> addr.tp.rx_id = 0x18DAF142 | CAN_EFF_FLAG;
>
Ack.
> > +
> > + ret = bind(s, (struct sockaddr *)&addr, sizeof(addr));
> > + if (ret < 0)
> > + exit(1);
> > +
> > + // Data can now be received using read(s, ...) and sent using write(s, ...)
>
> Kernel style prefers C style comments over C++. I think that should
> also apply to the documentation:
>
> /* Data can now be received using read(s, ...) and sent using write(s, ...) */
>
Ack.
Again, thank you for the review.
Regards,
Francesco
next prev parent reply other threads:[~2024-04-16 16:27 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-29 13:34 [PATCH v2 0/1] Documentation: networking: document ISO 15765-2:2016 Francesco Valla
2024-03-29 13:34 ` [PATCH v2 1/1] " Francesco Valla
2024-04-13 13:11 ` Vincent Mailhol
2024-04-13 17:28 ` Oliver Hartkopp
2024-04-14 4:03 ` Vincent Mailhol
2024-04-14 20:21 ` Oliver Hartkopp
2024-04-15 5:29 ` Vincent Mailhol
2024-04-16 16:42 ` Francesco Valla
2024-04-16 17:19 ` Oliver Hartkopp
2024-04-17 15:21 ` Vincent Mailhol
2024-04-20 19:51 ` Oliver Hartkopp
2024-04-21 20:41 ` Francesco Valla
2024-04-16 16:27 ` Francesco Valla [this message]
2024-04-17 15:26 ` Vincent Mailhol
2024-04-15 3:09 ` Bagas Sanjaya
2024-04-16 16:46 ` Francesco Valla
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Zh6m3jkRovDutKnZ@fedora \
--to=valla.francesco@gmail.com \
--cc=bagasdotme@gmail.com \
--cc=fabio@redaril.me \
--cc=horms@kernel.org \
--cc=linux-can@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mkl@pengutronix.de \
--cc=netdev@vger.kernel.org \
--cc=socketcan@hartkopp.net \
--cc=vincent.mailhol@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).