1 /** @file 2 * @brief Socket CAN definitions. 3 * 4 * Definitions for socket CAN support. 5 */ 6 7 /* 8 * Copyright (c) 2019 Intel Corporation 9 * 10 * SPDX-License-Identifier: Apache-2.0 11 */ 12 13 #ifndef ZEPHYR_INCLUDE_NET_SOCKET_CAN_H_ 14 #define ZEPHYR_INCLUDE_NET_SOCKET_CAN_H_ 15 16 #include <zephyr/types.h> 17 #include <net/net_ip.h> 18 #include <net/net_if.h> 19 #include <drivers/can.h> 20 21 #ifdef __cplusplus 22 extern "C" { 23 #endif 24 25 /** 26 * @brief Socket CAN library 27 * @defgroup socket_can Network Core Library 28 * @ingroup networking 29 * @{ 30 */ 31 32 /* Protocols of the protocol family PF_CAN */ 33 #define CAN_RAW 1 34 35 /* Socket CAN options */ 36 #define SOL_CAN_BASE 100 37 #define SOL_CAN_RAW (SOL_CAN_BASE + CAN_RAW) 38 39 enum { 40 CAN_RAW_FILTER = 1, 41 }; 42 43 /* Socket CAN MTU size */ 44 #define CAN_MTU CAN_MAX_DLEN 45 46 /** 47 * struct sockaddr_can - The sockaddr structure for CAN sockets 48 * 49 */ 50 struct sockaddr_can { 51 sa_family_t can_family; 52 int can_ifindex; 53 }; 54 55 /** 56 * CAN L2 driver API. Used by socket CAN. 57 */ 58 struct canbus_api { 59 /** 60 * The net_if_api must be placed in first position in this 61 * struct so that we are compatible with network interface API. 62 */ 63 struct net_if_api iface_api; 64 65 /** Send a CAN packet by socket */ 66 int (*send)(const struct device *dev, struct net_pkt *pkt); 67 68 /** Close the related CAN socket */ 69 void (*close)(const struct device *dev, int filter_id); 70 71 /** Set socket CAN option */ 72 int (*setsockopt)(const struct device *dev, void *obj, int level, 73 int optname, 74 const void *optval, socklen_t optlen); 75 76 /** Get socket CAN option */ 77 int (*getsockopt)(const struct device *dev, void *obj, int level, 78 int optname, 79 const void *optval, socklen_t *optlen); 80 }; 81 82 /* Make sure that the network interface API is properly setup inside 83 * CANBUS API struct (it is the first one). 84 */ 85 BUILD_ASSERT(offsetof(struct canbus_api, iface_api) == 0); 86 87 /** 88 * @} 89 */ 90 91 #ifdef __cplusplus 92 } 93 #endif 94 95 #endif /* ZEPHYR_INCLUDE_NET_SOCKET_CAN_H_ */ 96