Skip to content

Commit 31c4fd2

Browse files
karldingambv
authored andcommitted
bpo-37085: Expose SocketCAN bcm_msg_head flags (#13646)
Expose the CAN_BCM SocketCAN constants used in the bcm_msg_head struct flags (provided by <linux/can/bcm.h>) under the socket library. This adds the following constants with a CAN_BCM prefix: * SETTIMER * STARTTIMER * TX_COUNTEVT * TX_ANNOUNCE * TX_CP_CAN_ID * RX_FILTER_ID * RX_CHECK_DLC * RX_NO_AUTOTIMER * RX_ANNOUNCE_RESUME * TX_RESET_MULTI_IDX * RX_RTR_FRAME * CAN_FD_FRAME The CAN_FD_FRAME flag was introduced in the 4.8 kernel, while the other ones were present since SocketCAN drivers were mainlined in 2.6.25. As such, it is probably unnecessary to guard against these constants being missing.
1 parent 472eced commit 31c4fd2

File tree

5 files changed

+38
-0
lines changed

5 files changed

+38
-0
lines changed

Doc/library/socket.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,9 @@ Constants
391391

392392
.. availability:: Linux >= 2.6.25.
393393

394+
.. note::
395+
The :data:`CAN_BCM_CAN_FD_FRAME` flag is only available on Linux >= 4.8.
396+
394397
.. versionadded:: 3.4
395398

396399
.. data:: CAN_RAW_FD_FRAMES

Lib/test/test_socket.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1908,6 +1908,19 @@ def testBCMConstants(self):
19081908
socket.CAN_BCM_RX_TIMEOUT # cyclic message is absent
19091909
socket.CAN_BCM_RX_CHANGED # updated CAN frame (detected content change)
19101910

1911+
# flags
1912+
socket.CAN_BCM_SETTIMER
1913+
socket.CAN_BCM_STARTTIMER
1914+
socket.CAN_BCM_TX_COUNTEVT
1915+
socket.CAN_BCM_TX_ANNOUNCE
1916+
socket.CAN_BCM_TX_CP_CAN_ID
1917+
socket.CAN_BCM_RX_FILTER_ID
1918+
socket.CAN_BCM_RX_CHECK_DLC
1919+
socket.CAN_BCM_RX_NO_AUTOTIMER
1920+
socket.CAN_BCM_RX_ANNOUNCE_RESUME
1921+
socket.CAN_BCM_TX_RESET_MULTI_IDX
1922+
socket.CAN_BCM_RX_RTR_FRAME
1923+
19111924
def testCreateSocket(self):
19121925
with socket.socket(socket.PF_CAN, socket.SOCK_RAW, socket.CAN_RAW) as s:
19131926
pass

Misc/ACKS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,7 @@ Alon Diamant
397397
Toby Dickenson
398398
Mark Dickinson
399399
Jack Diederich
400+
Karl Ding
400401
Daniel Diniz
401402
Humberto Diogenes
402403
Yves Dionne
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Add the optional Linux SocketCAN Broadcast Manager constants, used as flags
2+
to configure the BCM behaviour, in the socket module. Patch by Karl Ding.

Modules/socketmodule.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7656,6 +7656,8 @@ PyInit__socket(void)
76567656
#endif
76577657
#ifdef HAVE_LINUX_CAN_BCM_H
76587658
PyModule_AddIntMacro(m, CAN_BCM);
7659+
7660+
/* BCM opcodes */
76597661
PyModule_AddIntConstant(m, "CAN_BCM_TX_SETUP", TX_SETUP);
76607662
PyModule_AddIntConstant(m, "CAN_BCM_TX_DELETE", TX_DELETE);
76617663
PyModule_AddIntConstant(m, "CAN_BCM_TX_READ", TX_READ);
@@ -7668,6 +7670,23 @@ PyInit__socket(void)
76687670
PyModule_AddIntConstant(m, "CAN_BCM_RX_STATUS", RX_STATUS);
76697671
PyModule_AddIntConstant(m, "CAN_BCM_RX_TIMEOUT", RX_TIMEOUT);
76707672
PyModule_AddIntConstant(m, "CAN_BCM_RX_CHANGED", RX_CHANGED);
7673+
7674+
/* BCM flags */
7675+
PyModule_AddIntConstant(m, "CAN_BCM_SETTIMER", SETTIMER);
7676+
PyModule_AddIntConstant(m, "CAN_BCM_STARTTIMER", STARTTIMER);
7677+
PyModule_AddIntConstant(m, "CAN_BCM_TX_COUNTEVT", TX_COUNTEVT);
7678+
PyModule_AddIntConstant(m, "CAN_BCM_TX_ANNOUNCE", TX_ANNOUNCE);
7679+
PyModule_AddIntConstant(m, "CAN_BCM_TX_CP_CAN_ID", TX_CP_CAN_ID);
7680+
PyModule_AddIntConstant(m, "CAN_BCM_RX_FILTER_ID", RX_FILTER_ID);
7681+
PyModule_AddIntConstant(m, "CAN_BCM_RX_CHECK_DLC", RX_CHECK_DLC);
7682+
PyModule_AddIntConstant(m, "CAN_BCM_RX_NO_AUTOTIMER", RX_NO_AUTOTIMER);
7683+
PyModule_AddIntConstant(m, "CAN_BCM_RX_ANNOUNCE_RESUME", RX_ANNOUNCE_RESUME);
7684+
PyModule_AddIntConstant(m, "CAN_BCM_TX_RESET_MULTI_IDX", TX_RESET_MULTI_IDX);
7685+
PyModule_AddIntConstant(m, "CAN_BCM_RX_RTR_FRAME", RX_RTR_FRAME);
7686+
#ifdef CAN_FD_FRAME
7687+
/* CAN_FD_FRAME was only introduced in the 4.8.x kernel series */
7688+
PyModule_AddIntConstant(m, "CAN_BCM_CAN_FD_FRAME", CAN_FD_FRAME);
7689+
#endif
76717690
#endif
76727691
#ifdef SOL_RDS
76737692
PyModule_AddIntMacro(m, SOL_RDS);

0 commit comments

Comments
 (0)