Home | History | Annotate | Line # | Download | only in netcan
      1  1.2  bouyer /*	$NetBSD: can_pcb.h,v 1.2 2017/05/27 21:02:56 bouyer Exp $	*/
      2  1.2  bouyer 
      3  1.2  bouyer /*-
      4  1.2  bouyer  * Copyright (c) 2003, 2017 The NetBSD Foundation, Inc.
      5  1.2  bouyer  * All rights reserved.
      6  1.2  bouyer  *
      7  1.2  bouyer  * This code is derived from software contributed to The NetBSD Foundation
      8  1.2  bouyer  * by Robert Swindells and Manuel Bouyer
      9  1.2  bouyer  *
     10  1.2  bouyer  * Redistribution and use in source and binary forms, with or without
     11  1.2  bouyer  * modification, are permitted provided that the following conditions
     12  1.2  bouyer  * are met:
     13  1.2  bouyer  * 1. Redistributions of source code must retain the above copyright
     14  1.2  bouyer  *    notice, this list of conditions and the following disclaimer.
     15  1.2  bouyer  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.2  bouyer  *    notice, this list of conditions and the following disclaimer in the
     17  1.2  bouyer  *    documentation and/or other materials provided with the distribution.
     18  1.2  bouyer  *
     19  1.2  bouyer  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20  1.2  bouyer  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21  1.2  bouyer  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22  1.2  bouyer  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23  1.2  bouyer  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24  1.2  bouyer  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25  1.2  bouyer  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26  1.2  bouyer  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27  1.2  bouyer  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28  1.2  bouyer  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29  1.2  bouyer  * POSSIBILITY OF SUCH DAMAGE.
     30  1.2  bouyer  */
     31  1.2  bouyer 
     32  1.2  bouyer #ifndef _NETCAN_CAN_PCB_H_
     33  1.2  bouyer #define _NETCAN_CAN_PCB_H_
     34  1.2  bouyer 
     35  1.2  bouyer #include <sys/queue.h>
     36  1.2  bouyer 
     37  1.2  bouyer /*
     38  1.2  bouyer  * Common structure pcb for can protocol implementation.
     39  1.2  bouyer  * Here are stored pointers to local and foreign host table
     40  1.2  bouyer  * entries, local and foreign socket numbers, and pointers
     41  1.2  bouyer  * up (to a socket structure) and down (to a protocol-specific)
     42  1.2  bouyer  * control block.
     43  1.2  bouyer  */
     44  1.2  bouyer struct canpcbpolicy;
     45  1.2  bouyer 
     46  1.2  bouyer 
     47  1.2  bouyer struct canpcb {
     48  1.2  bouyer 	LIST_ENTRY(canpcb) canp_hash;
     49  1.2  bouyer 	LIST_ENTRY(canpcb) canp_lhash;
     50  1.2  bouyer 	TAILQ_ENTRY(canpcb) canp_queue;
     51  1.2  bouyer 	kmutex_t 	canp_mtx;	/* protect states and refcount */
     52  1.2  bouyer 	int		canp_state;
     53  1.2  bouyer 	int		canp_flags;
     54  1.2  bouyer 	struct		socket *canp_socket;	/* back pointer to socket */
     55  1.2  bouyer 	struct		ifnet *canp_ifp; /* interface this socket is bound to */
     56  1.2  bouyer 
     57  1.2  bouyer 	struct		canpcbtable *canp_table;
     58  1.2  bouyer 	struct		can_filter *canp_filters; /* filter array */
     59  1.2  bouyer 	int		canp_nfilters; /* size of canp_filters */
     60  1.2  bouyer 
     61  1.2  bouyer 	int		canp_refcount;
     62  1.2  bouyer };
     63  1.2  bouyer 
     64  1.2  bouyer LIST_HEAD(canpcbhead, canpcb);
     65  1.2  bouyer 
     66  1.2  bouyer TAILQ_HEAD(canpcbqueue, canpcb);
     67  1.2  bouyer 
     68  1.2  bouyer struct canpcbtable {
     69  1.2  bouyer 	struct	canpcbqueue canpt_queue;
     70  1.2  bouyer 	struct	canpcbhead *canpt_bindhashtbl;
     71  1.2  bouyer 	struct	canpcbhead *canpt_connecthashtbl;
     72  1.2  bouyer 	u_long	canpt_bindhash;
     73  1.2  bouyer 	u_long	canpt_connecthash;
     74  1.2  bouyer };
     75  1.2  bouyer 
     76  1.2  bouyer /* states in canp_state: */
     77  1.2  bouyer #define	CANP_DETACHED		0
     78  1.2  bouyer #define	CANP_ATTACHED		1
     79  1.2  bouyer #define	CANP_BOUND		2
     80  1.2  bouyer #define	CANP_CONNECTED		3
     81  1.2  bouyer 
     82  1.2  bouyer /* flags in canp_flags: */
     83  1.2  bouyer #define CANP_NO_LOOPBACK	0x0001 /* local loopback disabled */
     84  1.2  bouyer #define CANP_RECEIVE_OWN	0x0002 /* receive own message */
     85  1.2  bouyer 
     86  1.2  bouyer 
     87  1.2  bouyer #define	sotocanpcb(so)		((struct canpcb *)(so)->so_pcb)
     88  1.2  bouyer 
     89  1.2  bouyer #ifdef _KERNEL
     90  1.2  bouyer void	can_losing(struct canpcb *);
     91  1.2  bouyer int	can_pcballoc (struct socket *, void *);
     92  1.2  bouyer int	can_pcbbind(void *, struct sockaddr_can *, struct lwp *);
     93  1.2  bouyer int	can_pcbconnect(void *, struct sockaddr_can *);
     94  1.2  bouyer void	can_pcbdetach(void *);
     95  1.2  bouyer void	can_pcbdisconnect(void *);
     96  1.2  bouyer void	can_pcbinit(struct canpcbtable *, int, int);
     97  1.2  bouyer int	can_pcbnotify(struct canpcbtable *, u_int32_t,
     98  1.2  bouyer 	    u_int32_t, int, void (*)(struct canpcb *, int));
     99  1.2  bouyer void	can_pcbnotifyall(struct canpcbtable *, u_int32_t, int,
    100  1.2  bouyer 	    void (*)(struct canpcb *, int));
    101  1.2  bouyer void	can_pcbpurgeif0(struct canpcbtable *, struct ifnet *);
    102  1.2  bouyer void	can_pcbpurgeif(struct canpcbtable *, struct ifnet *);
    103  1.2  bouyer void	can_pcbstate(struct canpcb *, int);
    104  1.2  bouyer void	can_setsockaddr(struct canpcb *, struct sockaddr_can *);
    105  1.2  bouyer int	can_pcbsetfilter(struct canpcb *, struct can_filter *, int);
    106  1.2  bouyer bool	can_pcbfilter(struct canpcb *, struct mbuf *);
    107  1.2  bouyer 
    108  1.2  bouyer /* refcount management */
    109  1.2  bouyer void	canp_ref(struct canpcb *);
    110  1.2  bouyer void	canp_unref(struct canpcb *);
    111  1.2  bouyer #endif
    112  1.2  bouyer 
    113  1.2  bouyer #endif /* _NETCAN_CAN_PCB_H_ */
    114