bpo-40291: Add support for CAN_J1939 sockets (GH-19538)

Add support for CAN_J1939 sockets that wrap SAE J1939 protocol
functionality provided by Linux 5.4+ kernels.
This commit is contained in:
karl ding 2020-04-29 15:31:19 -07:00 committed by GitHub
parent fd33cdbd05
commit 360371f79c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 197 additions and 5 deletions

View file

@ -118,6 +118,10 @@ created. Socket addresses are represented as follows:
- :const:`CAN_ISOTP` protocol require a tuple ``(interface, rx_addr, tx_addr)``
where both additional parameters are unsigned long integer that represent a
CAN identifier (standard or extended).
- :const:`CAN_J1939` protocol require a tuple ``(interface, name, pgn, addr)``
where additional parameters are 64-bit unsigned integer representing the
ECU name, a 32-bit unsigned integer representing the Parameter Group Number
(PGN), and an 8-bit integer representing the address.
- A string or a tuple ``(id, unit)`` is used for the :const:`SYSPROTO_CONTROL`
protocol of the :const:`PF_SYSTEM` family. The string is the name of a
@ -428,6 +432,15 @@ Constants
.. versionadded:: 3.7
.. data:: CAN_J1939
CAN_J1939, in the CAN protocol family, is the SAE J1939 protocol.
J1939 constants, documented in the Linux documentation.
.. availability:: Linux >= 5.4.
.. versionadded:: 3.9
.. data:: AF_PACKET
PF_PACKET
@ -544,7 +557,8 @@ The following functions all create :ref:`socket objects <socket-objects>`.
default), :const:`SOCK_DGRAM`, :const:`SOCK_RAW` or perhaps one of the other
``SOCK_`` constants. The protocol number is usually zero and may be omitted
or in the case where the address family is :const:`AF_CAN` the protocol
should be one of :const:`CAN_RAW`, :const:`CAN_BCM` or :const:`CAN_ISOTP`.
should be one of :const:`CAN_RAW`, :const:`CAN_BCM`, :const:`CAN_ISOTP` or
:const:`CAN_J1939`.
If *fileno* is specified, the values for *family*, *type*, and *proto* are
auto-detected from the specified file descriptor. Auto-detection can be
@ -588,6 +602,9 @@ The following functions all create :ref:`socket objects <socket-objects>`.
``SOCK_NONBLOCK``, but ``sock.type`` will be set to
``socket.SOCK_STREAM``.
.. versionchanged:: 3.9
The CAN_J1939 protocol was added.
.. function:: socketpair([family[, type[, proto]]])
Build a pair of connected socket objects using the given address family, socket