summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2019-07-31 09:10:38 (GMT)
committerGitHub <noreply@github.com>2019-07-31 09:10:38 (GMT)
commitd8b914a30b0849476345a19ce0a0ab1ade171b19 (patch)
tree56b9fdc45af96d67f50b4001cafca1802233d2d5
parent9b9cac4e5de975fe2417d8231822bc1d2ca2d273 (diff)
downloadcpython-d8b914a30b0849476345a19ce0a0ab1ade171b19.zip
cpython-d8b914a30b0849476345a19ce0a0ab1ade171b19.tar.gz
cpython-d8b914a30b0849476345a19ce0a0ab1ade171b19.tar.bz2
bpo-37085: Expose SocketCAN bcm_msg_head flags (GH-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. (cherry picked from commit 31c4fd2a10d90beaa37d630e5f74a471e14e089d) Co-authored-by: karl ding <karlding@users.noreply.github.com>
-rw-r--r--Doc/library/socket.rst3
-rw-r--r--Lib/test/test_socket.py13
-rw-r--r--Misc/ACKS1
-rw-r--r--Misc/NEWS.d/next/Library/2019-06-18-16-29-31.bpo-37085.GeYaD6.rst2
-rw-r--r--Modules/socketmodule.c19
5 files changed, 38 insertions, 0 deletions
diff --git a/Doc/library/socket.rst b/Doc/library/socket.rst
index f1010fb..12416e0 100644
--- a/Doc/library/socket.rst
+++ b/Doc/library/socket.rst
@@ -374,6 +374,9 @@ Constants
.. availability:: Linux >= 2.6.25.
+ .. note::
+ The :data:`CAN_BCM_CAN_FD_FRAME` flag is only available on Linux >= 4.8.
+
.. versionadded:: 3.4
.. data:: CAN_RAW_FD_FRAMES
diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py
index db52564..c472be1 100644
--- a/Lib/test/test_socket.py
+++ b/Lib/test/test_socket.py
@@ -1872,6 +1872,19 @@ class BasicCANTest(unittest.TestCase):
socket.CAN_BCM_RX_TIMEOUT # cyclic message is absent
socket.CAN_BCM_RX_CHANGED # updated CAN frame (detected content change)
+ # flags
+ socket.CAN_BCM_SETTIMER
+ socket.CAN_BCM_STARTTIMER
+ socket.CAN_BCM_TX_COUNTEVT
+ socket.CAN_BCM_TX_ANNOUNCE
+ socket.CAN_BCM_TX_CP_CAN_ID
+ socket.CAN_BCM_RX_FILTER_ID
+ socket.CAN_BCM_RX_CHECK_DLC
+ socket.CAN_BCM_RX_NO_AUTOTIMER
+ socket.CAN_BCM_RX_ANNOUNCE_RESUME
+ socket.CAN_BCM_TX_RESET_MULTI_IDX
+ socket.CAN_BCM_RX_RTR_FRAME
+
def testCreateSocket(self):
with socket.socket(socket.PF_CAN, socket.SOCK_RAW, socket.CAN_RAW) as s:
pass
diff --git a/Misc/ACKS b/Misc/ACKS
index a4973a8..829aa79 100644
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -395,6 +395,7 @@ Alon Diamant
Toby Dickenson
Mark Dickinson
Jack Diederich
+Karl Ding
Daniel Diniz
Humberto Diogenes
Yves Dionne
diff --git a/Misc/NEWS.d/next/Library/2019-06-18-16-29-31.bpo-37085.GeYaD6.rst b/Misc/NEWS.d/next/Library/2019-06-18-16-29-31.bpo-37085.GeYaD6.rst
new file mode 100644
index 0000000..e8db521
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2019-06-18-16-29-31.bpo-37085.GeYaD6.rst
@@ -0,0 +1,2 @@
+Add the optional Linux SocketCAN Broadcast Manager constants, used as flags
+to configure the BCM behaviour, in the socket module. Patch by Karl Ding.
diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c
index 36d13e7..0470f38 100644
--- a/Modules/socketmodule.c
+++ b/Modules/socketmodule.c
@@ -7656,6 +7656,8 @@ PyInit__socket(void)
#endif
#ifdef HAVE_LINUX_CAN_BCM_H
PyModule_AddIntMacro(m, CAN_BCM);
+
+ /* BCM opcodes */
PyModule_AddIntConstant(m, "CAN_BCM_TX_SETUP", TX_SETUP);
PyModule_AddIntConstant(m, "CAN_BCM_TX_DELETE", TX_DELETE);
PyModule_AddIntConstant(m, "CAN_BCM_TX_READ", TX_READ);
@@ -7668,6 +7670,23 @@ PyInit__socket(void)
PyModule_AddIntConstant(m, "CAN_BCM_RX_STATUS", RX_STATUS);
PyModule_AddIntConstant(m, "CAN_BCM_RX_TIMEOUT", RX_TIMEOUT);
PyModule_AddIntConstant(m, "CAN_BCM_RX_CHANGED", RX_CHANGED);
+
+ /* BCM flags */
+ PyModule_AddIntConstant(m, "CAN_BCM_SETTIMER", SETTIMER);
+ PyModule_AddIntConstant(m, "CAN_BCM_STARTTIMER", STARTTIMER);
+ PyModule_AddIntConstant(m, "CAN_BCM_TX_COUNTEVT", TX_COUNTEVT);
+ PyModule_AddIntConstant(m, "CAN_BCM_TX_ANNOUNCE", TX_ANNOUNCE);
+ PyModule_AddIntConstant(m, "CAN_BCM_TX_CP_CAN_ID", TX_CP_CAN_ID);
+ PyModule_AddIntConstant(m, "CAN_BCM_RX_FILTER_ID", RX_FILTER_ID);
+ PyModule_AddIntConstant(m, "CAN_BCM_RX_CHECK_DLC", RX_CHECK_DLC);
+ PyModule_AddIntConstant(m, "CAN_BCM_RX_NO_AUTOTIMER", RX_NO_AUTOTIMER);
+ PyModule_AddIntConstant(m, "CAN_BCM_RX_ANNOUNCE_RESUME", RX_ANNOUNCE_RESUME);
+ PyModule_AddIntConstant(m, "CAN_BCM_TX_RESET_MULTI_IDX", TX_RESET_MULTI_IDX);
+ PyModule_AddIntConstant(m, "CAN_BCM_RX_RTR_FRAME", RX_RTR_FRAME);
+#ifdef CAN_FD_FRAME
+ /* CAN_FD_FRAME was only introduced in the 4.8.x kernel series */
+ PyModule_AddIntConstant(m, "CAN_BCM_CAN_FD_FRAME", CAN_FD_FRAME);
+#endif
#endif
#ifdef SOL_RDS
PyModule_AddIntMacro(m, SOL_RDS);