xref: /openbmc/linux/include/linux/can/core.h (revision f726f3d3)
1fba76a58SOliver Hartkopp /* SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause) */
20d66548aSOliver Hartkopp /*
30d66548aSOliver Hartkopp  * linux/can/core.h
40d66548aSOliver Hartkopp  *
549347755SMarc Kleine-Budde  * Prototypes and definitions for CAN protocol modules using the PF_CAN core
60d66548aSOliver Hartkopp  *
70d66548aSOliver Hartkopp  * Authors: Oliver Hartkopp <oliver.hartkopp@volkswagen.de>
80d66548aSOliver Hartkopp  *          Urs Thuermann   <urs.thuermann@volkswagen.de>
9cb5635a3SOliver Hartkopp  * Copyright (c) 2002-2017 Volkswagen Group Electronic Research
100d66548aSOliver Hartkopp  * All rights reserved.
110d66548aSOliver Hartkopp  *
120d66548aSOliver Hartkopp  */
130d66548aSOliver Hartkopp 
1442193e3eSOliver Hartkopp #ifndef _CAN_CORE_H
1542193e3eSOliver Hartkopp #define _CAN_CORE_H
160d66548aSOliver Hartkopp 
170d66548aSOliver Hartkopp #include <linux/can.h>
180d66548aSOliver Hartkopp #include <linux/skbuff.h>
190d66548aSOliver Hartkopp #include <linux/netdevice.h>
200d66548aSOliver Hartkopp 
210d66548aSOliver Hartkopp #define DNAME(dev) ((dev) ? (dev)->name : "any")
220d66548aSOliver Hartkopp 
230d66548aSOliver Hartkopp /**
240d66548aSOliver Hartkopp  * struct can_proto - CAN protocol structure
250d66548aSOliver Hartkopp  * @type:       type argument in socket() syscall, e.g. SOCK_DGRAM.
260d66548aSOliver Hartkopp  * @protocol:   protocol number in socket() syscall.
270d66548aSOliver Hartkopp  * @ops:        pointer to struct proto_ops for sock->ops.
280d66548aSOliver Hartkopp  * @prot:       pointer to struct proto structure.
290d66548aSOliver Hartkopp  */
300d66548aSOliver Hartkopp struct can_proto {
310d66548aSOliver Hartkopp 	int type;
320d66548aSOliver Hartkopp 	int protocol;
3353914b67SOliver Hartkopp 	const struct proto_ops *ops;
340d66548aSOliver Hartkopp 	struct proto *prot;
350d66548aSOliver Hartkopp };
360d66548aSOliver Hartkopp 
379868b5d4SKurt Van Dijck /* required_size
389868b5d4SKurt Van Dijck  * macro to find the minimum size of a struct
399868b5d4SKurt Van Dijck  * that includes a requested member
409868b5d4SKurt Van Dijck  */
419868b5d4SKurt Van Dijck #define CAN_REQUIRED_SIZE(struct_type, member) \
429868b5d4SKurt Van Dijck 	(offsetof(typeof(struct_type), member) + \
439868b5d4SKurt Van Dijck 	 sizeof(((typeof(struct_type) *)(NULL))->member))
449868b5d4SKurt Van Dijck 
450d66548aSOliver Hartkopp /* function prototypes for the CAN networklayer core (af_can.c) */
460d66548aSOliver Hartkopp 
471650629dSKurt Van Dijck extern int  can_proto_register(const struct can_proto *cp);
481650629dSKurt Van Dijck extern void can_proto_unregister(const struct can_proto *cp);
490d66548aSOliver Hartkopp 
508e8cda6dSMario Kicherer int can_rx_register(struct net *net, struct net_device *dev,
518e8cda6dSMario Kicherer 		    canid_t can_id, canid_t mask,
520d66548aSOliver Hartkopp 		    void (*func)(struct sk_buff *, void *),
53f1712c73SEric Dumazet 		    void *data, char *ident, struct sock *sk);
540d66548aSOliver Hartkopp 
558e8cda6dSMario Kicherer extern void can_rx_unregister(struct net *net, struct net_device *dev,
568e8cda6dSMario Kicherer 			      canid_t can_id, canid_t mask,
570d66548aSOliver Hartkopp 			      void (*func)(struct sk_buff *, void *),
580d66548aSOliver Hartkopp 			      void *data);
590d66548aSOliver Hartkopp 
600d66548aSOliver Hartkopp extern int can_send(struct sk_buff *skb, int loop);
61975987e7SOleksij Rempel void can_sock_destruct(struct sock *sk);
620d66548aSOliver Hartkopp 
6342193e3eSOliver Hartkopp #endif /* !_CAN_CORE_H */
64