blob: dbef5917905be5eb38116d1e88000a857900be07 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#ifndef LLC_H
2#define LLC_H
3/*
4 * Copyright (c) 1997 by Procom Technology, Inc.
5 * 2001-2003 by Arnaldo Carvalho de Melo <acme@conectiva.com.br>
6 *
7 * This program can be redistributed or modified under the terms of the
8 * GNU General Public License as published by the Free Software Foundation.
9 * This program is distributed without any warranty or implied warranty
10 * of merchantability or fitness for a particular purpose.
11 *
12 * See the GNU General Public License for more details.
13 */
14
15#include <linux/if.h>
16#include <linux/if_ether.h>
17#include <linux/list.h>
18#include <linux/spinlock.h>
Octavian Purdilab76f5a82009-12-26 11:51:02 +000019#include <linux/rculist_nulls.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070020
Arnaldo Carvalho de Melo6e2144b2005-09-22 04:43:05 -030021#include <asm/atomic.h>
22
Linus Torvalds1da177e2005-04-16 15:20:36 -070023struct net_device;
24struct packet_type;
25struct sk_buff;
26
27struct llc_addr {
28 unsigned char lsap;
29 unsigned char mac[IFHWADDRLEN];
30};
31
32#define LLC_SAP_STATE_INACTIVE 1
33#define LLC_SAP_STATE_ACTIVE 2
34
Octavian Purdila6d2e3ea2009-12-26 11:51:04 +000035#define LLC_SK_DEV_HASH_BITS 6
36#define LLC_SK_DEV_HASH_ENTRIES (1<<LLC_SK_DEV_HASH_BITS)
37
Linus Torvalds1da177e2005-04-16 15:20:36 -070038/**
39 * struct llc_sap - Defines the SAP component
40 *
41 * @station - station this sap belongs to
42 * @state - sap state
43 * @p_bit - only lowest-order bit used
44 * @f_bit - only lowest-order bit used
45 * @laddr - SAP value in this 'lsap'
46 * @node - entry in station sap_list
47 * @sk_list - LLC sockets this one manages
48 */
49struct llc_sap {
50 unsigned char state;
51 unsigned char p_bit;
52 unsigned char f_bit;
Arnaldo Carvalho de Melo6e2144b2005-09-22 04:43:05 -030053 atomic_t refcnt;
Linus Torvalds1da177e2005-04-16 15:20:36 -070054 int (*rcv_func)(struct sk_buff *skb,
55 struct net_device *dev,
David S. Millerf2ccd8f2005-08-09 19:34:12 -070056 struct packet_type *pt,
57 struct net_device *orig_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -070058 struct llc_addr laddr;
59 struct list_head node;
Octavian Purdilab76f5a82009-12-26 11:51:02 +000060 spinlock_t sk_lock;
61 struct hlist_nulls_head sk_list;
Octavian Purdila6d2e3ea2009-12-26 11:51:04 +000062 struct hlist_head sk_dev_hash[LLC_SK_DEV_HASH_ENTRIES];
Linus Torvalds1da177e2005-04-16 15:20:36 -070063};
64
Octavian Purdila6d2e3ea2009-12-26 11:51:04 +000065static inline
66struct hlist_head *llc_sk_dev_hash(struct llc_sap *sap, int ifindex)
67{
68 return &sap->sk_dev_hash[ifindex % LLC_SK_DEV_HASH_ENTRIES];
69}
70
71
Linus Torvalds1da177e2005-04-16 15:20:36 -070072#define LLC_DEST_INVALID 0 /* Invalid LLC PDU type */
73#define LLC_DEST_SAP 1 /* Type 1 goes here */
74#define LLC_DEST_CONN 2 /* Type 2 goes here */
75
76extern struct list_head llc_sap_list;
77extern rwlock_t llc_sap_list_lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -070078
79extern int llc_rcv(struct sk_buff *skb, struct net_device *dev,
David S. Millerf2ccd8f2005-08-09 19:34:12 -070080 struct packet_type *pt, struct net_device *orig_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -070081
82extern int llc_mac_hdr_init(struct sk_buff *skb,
Stephen Hemmingerf4ad2b12006-03-20 22:59:36 -080083 const unsigned char *sa, const unsigned char *da);
Linus Torvalds1da177e2005-04-16 15:20:36 -070084
85extern void llc_add_pack(int type, void (*handler)(struct llc_sap *sap,
86 struct sk_buff *skb));
87extern void llc_remove_pack(int type);
88
89extern void llc_set_station_handler(void (*handler)(struct sk_buff *skb));
90
91extern struct llc_sap *llc_sap_open(unsigned char lsap,
92 int (*rcv)(struct sk_buff *skb,
93 struct net_device *dev,
David S. Millerf2ccd8f2005-08-09 19:34:12 -070094 struct packet_type *pt,
95 struct net_device *orig_dev));
Arnaldo Carvalho de Melo6e2144b2005-09-22 04:43:05 -030096static inline void llc_sap_hold(struct llc_sap *sap)
97{
98 atomic_inc(&sap->refcnt);
99}
100
Arnaldo Carvalho de Melo2928c192005-09-22 05:14:33 -0300101extern void llc_sap_close(struct llc_sap *sap);
102
Arnaldo Carvalho de Melo6e2144b2005-09-22 04:43:05 -0300103static inline void llc_sap_put(struct llc_sap *sap)
104{
Arnaldo Carvalho de Melo6e2144b2005-09-22 04:43:05 -0300105 if (atomic_dec_and_test(&sap->refcnt))
106 llc_sap_close(sap);
107}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108
109extern struct llc_sap *llc_sap_find(unsigned char sap_value);
110
111extern int llc_build_and_send_ui_pkt(struct llc_sap *sap, struct sk_buff *skb,
112 unsigned char *dmac, unsigned char dsap);
113
Arnaldo Carvalho de Melo2928c192005-09-22 05:14:33 -0300114extern void llc_sap_handler(struct llc_sap *sap, struct sk_buff *skb);
115extern void llc_conn_handler(struct llc_sap *sap, struct sk_buff *skb);
116
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117extern int llc_station_init(void);
118extern void llc_station_exit(void);
119
120#ifdef CONFIG_PROC_FS
121extern int llc_proc_init(void);
122extern void llc_proc_exit(void);
123#else
124#define llc_proc_init() (0)
125#define llc_proc_exit() do { } while(0)
126#endif /* CONFIG_PROC_FS */
Arnaldo Carvalho de Melo590232a2005-09-22 04:30:44 -0300127#ifdef CONFIG_SYSCTL
128extern int llc_sysctl_init(void);
129extern void llc_sysctl_exit(void);
Arnaldo Carvalho de Melo2928c192005-09-22 05:14:33 -0300130
131extern int sysctl_llc2_ack_timeout;
132extern int sysctl_llc2_busy_timeout;
133extern int sysctl_llc2_p_timeout;
134extern int sysctl_llc2_rej_timeout;
135extern int sysctl_llc_station_ack_timeout;
Arnaldo Carvalho de Melo590232a2005-09-22 04:30:44 -0300136#else
137#define llc_sysctl_init() (0)
138#define llc_sysctl_exit() do { } while(0)
139#endif /* CONFIG_SYSCTL */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140#endif /* LLC_H */