-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Remove dependence on special Python builds for CAN functionality
The CAN constants are compiled in depending in the enabled kernel features. In case a Python interpreter is built in a special environment (e.g., https://github.com/indygreg/python-build-standalone used by the uv tool), then a few constants might be missing. The absence of these constants does not limit the availability of the CAN feature on a supported kernel. So, lets checkin a generated file with the correct constants to avoid running into this problem.
- Loading branch information
1 parent
23a34cd
commit db4e636
Showing
4 changed files
with
126 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#!/usr/bin/env python | ||
|
||
# SPDX-FileCopyrightText: AISEC Pentesting Team | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
import socket | ||
|
||
|
||
TEMPLATE = f"""# This file has been autogenerated by `make constants`. | ||
# !! DO NOT CHANGE MANUALLY !! | ||
# SPDX-FileCopyrightText: AISEC Pentesting Team | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
import struct | ||
CANFD_MTU = 72 | ||
CAN_MTU = 16 | ||
# https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/include/uapi/linux/can.h | ||
CAN_HEADER_FMT = struct.Struct("=IBB2x") | ||
CANFD_BRS = 0x01 | ||
CANFD_ESI = 0x02 | ||
CAN_EFF_FLAG = {socket.CAN_EFF_FLAG} | ||
CAN_ERR_FLAG = {socket.CAN_ERR_FLAG} | ||
CAN_RTR_FLAG = {socket.CAN_RTR_FLAG} | ||
CAN_EFF_MASK = {socket.CAN_EFF_MASK} | ||
CAN_INV_FILTER = 0x20000000 # TODO: Add to CPython | ||
CAN_SFF_MASK = {socket.CAN_SFF_MASK} | ||
CAN_RAW = {socket.CAN_RAW} | ||
CAN_RAW_FD_FRAMES = {socket.CAN_RAW_FD_FRAMES} | ||
CAN_RAW_FILTER = {socket.CAN_RAW_FILTER} | ||
CAN_RAW_JOIN_FILTERS = {socket.CAN_RAW_JOIN_FILTERS} | ||
SOL_CAN_RAW = {socket.SOL_CAN_RAW} | ||
""" | ||
|
||
|
||
def main() -> None: | ||
print(TEMPLATE) | ||
|
||
|
||
if __name__ == "__main__": | ||
try: | ||
main() | ||
except KeyboardInterrupt: | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# This file has been autogenerated by `make constants`. | ||
# !! DO NOT CHANGE MANUALLY !! | ||
|
||
# SPDX-FileCopyrightText: AISEC Pentesting Team | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
import struct | ||
|
||
CANFD_MTU = 72 | ||
CAN_MTU = 16 | ||
|
||
# https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/include/uapi/linux/can.h | ||
CAN_HEADER_FMT = struct.Struct("=IBB2x") | ||
|
||
CANFD_BRS = 0x01 | ||
CANFD_ESI = 0x02 | ||
|
||
CAN_EFF_FLAG = 2147483648 | ||
CAN_ERR_FLAG = 536870912 | ||
CAN_RTR_FLAG = 1073741824 | ||
|
||
CAN_EFF_MASK = 536870911 | ||
CAN_INV_FILTER = 0x20000000 # TODO: Add to CPython | ||
CAN_SFF_MASK = 2047 | ||
|
||
CAN_RAW = 1 | ||
CAN_RAW_FD_FRAMES = 5 | ||
CAN_RAW_FILTER = 1 | ||
CAN_RAW_JOIN_FILTERS = 6 | ||
SOL_CAN_RAW = 101 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters