0001
0002
0003
0004
0005
0006
0007 #ifndef _AX25_H
0008 #define _AX25_H
0009
0010 #include <linux/ax25.h>
0011 #include <linux/spinlock.h>
0012 #include <linux/timer.h>
0013 #include <linux/list.h>
0014 #include <linux/slab.h>
0015 #include <linux/refcount.h>
0016 #include <net/neighbour.h>
0017 #include <net/sock.h>
0018 #include <linux/seq_file.h>
0019
0020 #define AX25_T1CLAMPLO 1
0021 #define AX25_T1CLAMPHI (30 * HZ)
0022
0023 #define AX25_BPQ_HEADER_LEN 16
0024 #define AX25_KISS_HEADER_LEN 1
0025
0026 #define AX25_HEADER_LEN 17
0027 #define AX25_ADDR_LEN 7
0028 #define AX25_DIGI_HEADER_LEN (AX25_MAX_DIGIS * AX25_ADDR_LEN)
0029 #define AX25_MAX_HEADER_LEN (AX25_HEADER_LEN + AX25_DIGI_HEADER_LEN)
0030
0031
0032 #define AX25_P_ROSE 0x01
0033 #define AX25_P_VJCOMP 0x06
0034
0035 #define AX25_P_VJUNCOMP 0x07
0036
0037 #define AX25_P_SEGMENT 0x08
0038 #define AX25_P_TEXNET 0xc3
0039 #define AX25_P_LQ 0xc4
0040 #define AX25_P_ATALK 0xca
0041 #define AX25_P_ATALK_ARP 0xcb
0042 #define AX25_P_IP 0xcc
0043 #define AX25_P_ARP 0xcd
0044 #define AX25_P_FLEXNET 0xce
0045 #define AX25_P_NETROM 0xcf
0046 #define AX25_P_TEXT 0xF0
0047
0048
0049 #define AX25_SEG_REM 0x7F
0050 #define AX25_SEG_FIRST 0x80
0051
0052 #define AX25_CBIT 0x80
0053 #define AX25_EBIT 0x01
0054 #define AX25_HBIT 0x80
0055
0056 #define AX25_SSSID_SPARE 0x60
0057 #define AX25_ESSID_SPARE 0x20
0058 #define AX25_DAMA_FLAG 0x20
0059
0060 #define AX25_COND_ACK_PENDING 0x01
0061 #define AX25_COND_REJECT 0x02
0062 #define AX25_COND_PEER_RX_BUSY 0x04
0063 #define AX25_COND_OWN_RX_BUSY 0x08
0064 #define AX25_COND_DAMA_MODE 0x10
0065
0066 #ifndef _LINUX_NETDEVICE_H
0067 #include <linux/netdevice.h>
0068 #endif
0069
0070
0071
0072
0073 #define AX25_I 0x00
0074 #define AX25_S 0x01
0075 #define AX25_RR 0x01
0076 #define AX25_RNR 0x05
0077 #define AX25_REJ 0x09
0078 #define AX25_U 0x03
0079 #define AX25_SABM 0x2f
0080 #define AX25_SABME 0x6f
0081 #define AX25_DISC 0x43
0082 #define AX25_DM 0x0f
0083 #define AX25_UA 0x63
0084 #define AX25_FRMR 0x87
0085 #define AX25_UI 0x03
0086 #define AX25_XID 0xaf
0087 #define AX25_TEST 0xe3
0088
0089 #define AX25_PF 0x10
0090 #define AX25_EPF 0x01
0091
0092 #define AX25_ILLEGAL 0x100
0093
0094 #define AX25_POLLOFF 0
0095 #define AX25_POLLON 1
0096
0097
0098 #define AX25_COMMAND 1
0099 #define AX25_RESPONSE 2
0100
0101
0102
0103 enum {
0104 AX25_STATE_0,
0105 AX25_STATE_1,
0106 AX25_STATE_2,
0107 AX25_STATE_3,
0108 AX25_STATE_4
0109 };
0110
0111 #define AX25_MODULUS 8
0112 #define AX25_EMODULUS 128
0113
0114 enum {
0115 AX25_PROTO_STD_SIMPLEX,
0116 AX25_PROTO_STD_DUPLEX,
0117 #ifdef CONFIG_AX25_DAMA_SLAVE
0118 AX25_PROTO_DAMA_SLAVE,
0119 #ifdef CONFIG_AX25_DAMA_MASTER
0120 AX25_PROTO_DAMA_MASTER,
0121 #define AX25_PROTO_MAX AX25_PROTO_DAMA_MASTER
0122 #endif
0123 #endif
0124 __AX25_PROTO_MAX,
0125 AX25_PROTO_MAX = __AX25_PROTO_MAX -1
0126 };
0127
0128 enum {
0129 AX25_VALUES_IPDEFMODE,
0130 AX25_VALUES_AXDEFMODE,
0131 AX25_VALUES_BACKOFF,
0132 AX25_VALUES_CONMODE,
0133 AX25_VALUES_WINDOW,
0134 AX25_VALUES_EWINDOW,
0135 AX25_VALUES_T1,
0136 AX25_VALUES_T2,
0137 AX25_VALUES_T3,
0138 AX25_VALUES_IDLE,
0139 AX25_VALUES_N2,
0140 AX25_VALUES_PACLEN,
0141 AX25_VALUES_PROTOCOL,
0142 AX25_VALUES_DS_TIMEOUT,
0143 AX25_MAX_VALUES
0144 };
0145
0146 #define AX25_DEF_IPDEFMODE 0
0147 #define AX25_DEF_AXDEFMODE 0
0148 #define AX25_DEF_BACKOFF 1
0149 #define AX25_DEF_CONMODE 2
0150 #define AX25_DEF_WINDOW 2
0151 #define AX25_DEF_EWINDOW 32
0152 #define AX25_DEF_T1 10000
0153 #define AX25_DEF_T2 3000
0154 #define AX25_DEF_T3 300000
0155 #define AX25_DEF_N2 10
0156 #define AX25_DEF_IDLE 0
0157 #define AX25_DEF_PACLEN 256
0158 #define AX25_DEF_PROTOCOL AX25_PROTO_STD_SIMPLEX
0159 #define AX25_DEF_DS_TIMEOUT 180000
0160
0161 typedef struct ax25_uid_assoc {
0162 struct hlist_node uid_node;
0163 refcount_t refcount;
0164 kuid_t uid;
0165 ax25_address call;
0166 } ax25_uid_assoc;
0167
0168 #define ax25_uid_for_each(__ax25, list) \
0169 hlist_for_each_entry(__ax25, list, uid_node)
0170
0171 #define ax25_uid_hold(ax25) \
0172 refcount_inc(&((ax25)->refcount))
0173
0174 static inline void ax25_uid_put(ax25_uid_assoc *assoc)
0175 {
0176 if (refcount_dec_and_test(&assoc->refcount)) {
0177 kfree(assoc);
0178 }
0179 }
0180
0181 typedef struct {
0182 ax25_address calls[AX25_MAX_DIGIS];
0183 unsigned char repeated[AX25_MAX_DIGIS];
0184 unsigned char ndigi;
0185 signed char lastrepeat;
0186 } ax25_digi;
0187
0188 typedef struct ax25_route {
0189 struct ax25_route *next;
0190 ax25_address callsign;
0191 struct net_device *dev;
0192 ax25_digi *digipeat;
0193 char ip_mode;
0194 } ax25_route;
0195
0196 void __ax25_put_route(ax25_route *ax25_rt);
0197
0198 extern rwlock_t ax25_route_lock;
0199
0200 static inline void ax25_route_lock_use(void)
0201 {
0202 read_lock(&ax25_route_lock);
0203 }
0204
0205 static inline void ax25_route_lock_unuse(void)
0206 {
0207 read_unlock(&ax25_route_lock);
0208 }
0209
0210 typedef struct {
0211 char slave;
0212 struct timer_list slave_timer;
0213 unsigned short slave_timeout;
0214 } ax25_dama_info;
0215
0216 struct ctl_table;
0217
0218 typedef struct ax25_dev {
0219 struct ax25_dev *next;
0220
0221 struct net_device *dev;
0222 netdevice_tracker dev_tracker;
0223
0224 struct net_device *forward;
0225 struct ctl_table_header *sysheader;
0226 int values[AX25_MAX_VALUES];
0227 #if defined(CONFIG_AX25_DAMA_SLAVE) || defined(CONFIG_AX25_DAMA_MASTER)
0228 ax25_dama_info dama;
0229 #endif
0230 refcount_t refcount;
0231 bool device_up;
0232 } ax25_dev;
0233
0234 typedef struct ax25_cb {
0235 struct hlist_node ax25_node;
0236 ax25_address source_addr, dest_addr;
0237 ax25_digi *digipeat;
0238 ax25_dev *ax25_dev;
0239 netdevice_tracker dev_tracker;
0240 unsigned char iamdigi;
0241 unsigned char state, modulus, pidincl;
0242 unsigned short vs, vr, va;
0243 unsigned char condition, backoff;
0244 unsigned char n2, n2count;
0245 struct timer_list t1timer, t2timer, t3timer, idletimer;
0246 unsigned long t1, t2, t3, idle, rtt;
0247 unsigned short paclen, fragno, fraglen;
0248 struct sk_buff_head write_queue;
0249 struct sk_buff_head reseq_queue;
0250 struct sk_buff_head ack_queue;
0251 struct sk_buff_head frag_queue;
0252 unsigned char window;
0253 struct timer_list timer, dtimer;
0254 struct sock *sk;
0255 refcount_t refcount;
0256 } ax25_cb;
0257
0258 struct ax25_sock {
0259 struct sock sk;
0260 struct ax25_cb *cb;
0261 };
0262
0263 static inline struct ax25_sock *ax25_sk(const struct sock *sk)
0264 {
0265 return (struct ax25_sock *) sk;
0266 }
0267
0268 static inline struct ax25_cb *sk_to_ax25(const struct sock *sk)
0269 {
0270 return ax25_sk(sk)->cb;
0271 }
0272
0273 #define ax25_for_each(__ax25, list) \
0274 hlist_for_each_entry(__ax25, list, ax25_node)
0275
0276 #define ax25_cb_hold(__ax25) \
0277 refcount_inc(&((__ax25)->refcount))
0278
0279 static __inline__ void ax25_cb_put(ax25_cb *ax25)
0280 {
0281 if (refcount_dec_and_test(&ax25->refcount)) {
0282 kfree(ax25->digipeat);
0283 kfree(ax25);
0284 }
0285 }
0286
0287 static inline void ax25_dev_hold(ax25_dev *ax25_dev)
0288 {
0289 refcount_inc(&ax25_dev->refcount);
0290 }
0291
0292 static inline void ax25_dev_put(ax25_dev *ax25_dev)
0293 {
0294 if (refcount_dec_and_test(&ax25_dev->refcount)) {
0295 kfree(ax25_dev);
0296 }
0297 }
0298 static inline __be16 ax25_type_trans(struct sk_buff *skb, struct net_device *dev)
0299 {
0300 skb->dev = dev;
0301 skb_reset_mac_header(skb);
0302 skb->pkt_type = PACKET_HOST;
0303 return htons(ETH_P_AX25);
0304 }
0305
0306
0307 extern struct hlist_head ax25_list;
0308 extern spinlock_t ax25_list_lock;
0309 void ax25_cb_add(ax25_cb *);
0310 struct sock *ax25_find_listener(ax25_address *, int, struct net_device *, int);
0311 struct sock *ax25_get_socket(ax25_address *, ax25_address *, int);
0312 ax25_cb *ax25_find_cb(const ax25_address *, ax25_address *, ax25_digi *,
0313 struct net_device *);
0314 void ax25_send_to_raw(ax25_address *, struct sk_buff *, int);
0315 void ax25_destroy_socket(ax25_cb *);
0316 ax25_cb * __must_check ax25_create_cb(void);
0317 void ax25_fillin_cb(ax25_cb *, ax25_dev *);
0318 struct sock *ax25_make_new(struct sock *, struct ax25_dev *);
0319
0320
0321 extern const ax25_address ax25_bcast;
0322 extern const ax25_address ax25_defaddr;
0323 extern const ax25_address null_ax25_address;
0324 char *ax2asc(char *buf, const ax25_address *);
0325 void asc2ax(ax25_address *addr, const char *callsign);
0326 int ax25cmp(const ax25_address *, const ax25_address *);
0327 int ax25digicmp(const ax25_digi *, const ax25_digi *);
0328 const unsigned char *ax25_addr_parse(const unsigned char *, int,
0329 ax25_address *, ax25_address *, ax25_digi *, int *, int *);
0330 int ax25_addr_build(unsigned char *, const ax25_address *,
0331 const ax25_address *, const ax25_digi *, int, int);
0332 int ax25_addr_size(const ax25_digi *);
0333 void ax25_digi_invert(const ax25_digi *, ax25_digi *);
0334
0335
0336 extern ax25_dev *ax25_dev_list;
0337 extern spinlock_t ax25_dev_lock;
0338
0339 #if IS_ENABLED(CONFIG_AX25)
0340 static inline ax25_dev *ax25_dev_ax25dev(struct net_device *dev)
0341 {
0342 return dev->ax25_ptr;
0343 }
0344 #endif
0345
0346 ax25_dev *ax25_addr_ax25dev(ax25_address *);
0347 void ax25_dev_device_up(struct net_device *);
0348 void ax25_dev_device_down(struct net_device *);
0349 int ax25_fwd_ioctl(unsigned int, struct ax25_fwd_struct *);
0350 struct net_device *ax25_fwd_dev(struct net_device *);
0351 void ax25_dev_free(void);
0352
0353
0354 int ax25_ds_frame_in(ax25_cb *, struct sk_buff *, int);
0355
0356
0357 void ax25_ds_nr_error_recovery(ax25_cb *);
0358 void ax25_ds_enquiry_response(ax25_cb *);
0359 void ax25_ds_establish_data_link(ax25_cb *);
0360 void ax25_dev_dama_off(ax25_dev *);
0361 void ax25_dama_on(ax25_cb *);
0362 void ax25_dama_off(ax25_cb *);
0363
0364
0365 void ax25_ds_setup_timer(ax25_dev *);
0366 void ax25_ds_set_timer(ax25_dev *);
0367 void ax25_ds_del_timer(ax25_dev *);
0368 void ax25_ds_timer(ax25_cb *);
0369 void ax25_ds_t1_timeout(ax25_cb *);
0370 void ax25_ds_heartbeat_expiry(ax25_cb *);
0371 void ax25_ds_t3timer_expiry(ax25_cb *);
0372 void ax25_ds_idletimer_expiry(ax25_cb *);
0373
0374
0375
0376 struct ax25_protocol {
0377 struct ax25_protocol *next;
0378 unsigned int pid;
0379 int (*func)(struct sk_buff *, ax25_cb *);
0380 };
0381
0382 void ax25_register_pid(struct ax25_protocol *ap);
0383 void ax25_protocol_release(unsigned int);
0384
0385 struct ax25_linkfail {
0386 struct hlist_node lf_node;
0387 void (*func)(ax25_cb *, int);
0388 };
0389
0390 void ax25_linkfail_register(struct ax25_linkfail *lf);
0391 void ax25_linkfail_release(struct ax25_linkfail *lf);
0392 int __must_check ax25_listen_register(const ax25_address *,
0393 struct net_device *);
0394 void ax25_listen_release(const ax25_address *, struct net_device *);
0395 int(*ax25_protocol_function(unsigned int))(struct sk_buff *, ax25_cb *);
0396 int ax25_listen_mine(const ax25_address *, struct net_device *);
0397 void ax25_link_failed(ax25_cb *, int);
0398 int ax25_protocol_is_registered(unsigned int);
0399
0400
0401 int ax25_rx_iframe(ax25_cb *, struct sk_buff *);
0402 int ax25_kiss_rcv(struct sk_buff *, struct net_device *, struct packet_type *,
0403 struct net_device *);
0404
0405
0406 netdev_tx_t ax25_ip_xmit(struct sk_buff *skb);
0407 extern const struct header_ops ax25_header_ops;
0408
0409
0410 ax25_cb *ax25_send_frame(struct sk_buff *, int, const ax25_address *,
0411 ax25_address *, ax25_digi *, struct net_device *);
0412 void ax25_output(ax25_cb *, int, struct sk_buff *);
0413 void ax25_kick(ax25_cb *);
0414 void ax25_transmit_buffer(ax25_cb *, struct sk_buff *, int);
0415 void ax25_queue_xmit(struct sk_buff *skb, struct net_device *dev);
0416 int ax25_check_iframes_acked(ax25_cb *, unsigned short);
0417
0418
0419 void ax25_rt_device_down(struct net_device *);
0420 int ax25_rt_ioctl(unsigned int, void __user *);
0421 extern const struct seq_operations ax25_rt_seqops;
0422 ax25_route *ax25_get_route(ax25_address *addr, struct net_device *dev);
0423 int ax25_rt_autobind(ax25_cb *, ax25_address *);
0424 struct sk_buff *ax25_rt_build_path(struct sk_buff *, ax25_address *,
0425 ax25_address *, ax25_digi *);
0426 void ax25_rt_free(void);
0427
0428
0429 int ax25_std_frame_in(ax25_cb *, struct sk_buff *, int);
0430
0431
0432 void ax25_std_nr_error_recovery(ax25_cb *);
0433 void ax25_std_establish_data_link(ax25_cb *);
0434 void ax25_std_transmit_enquiry(ax25_cb *);
0435 void ax25_std_enquiry_response(ax25_cb *);
0436 void ax25_std_timeout_response(ax25_cb *);
0437
0438
0439 void ax25_std_heartbeat_expiry(ax25_cb *);
0440 void ax25_std_t1timer_expiry(ax25_cb *);
0441 void ax25_std_t2timer_expiry(ax25_cb *);
0442 void ax25_std_t3timer_expiry(ax25_cb *);
0443 void ax25_std_idletimer_expiry(ax25_cb *);
0444
0445
0446 void ax25_clear_queues(ax25_cb *);
0447 void ax25_frames_acked(ax25_cb *, unsigned short);
0448 void ax25_requeue_frames(ax25_cb *);
0449 int ax25_validate_nr(ax25_cb *, unsigned short);
0450 int ax25_decode(ax25_cb *, struct sk_buff *, int *, int *, int *);
0451 void ax25_send_control(ax25_cb *, int, int, int);
0452 void ax25_return_dm(struct net_device *, ax25_address *, ax25_address *,
0453 ax25_digi *);
0454 void ax25_calculate_t1(ax25_cb *);
0455 void ax25_calculate_rtt(ax25_cb *);
0456 void ax25_disconnect(ax25_cb *, int);
0457
0458
0459 void ax25_setup_timers(ax25_cb *);
0460 void ax25_start_heartbeat(ax25_cb *);
0461 void ax25_start_t1timer(ax25_cb *);
0462 void ax25_start_t2timer(ax25_cb *);
0463 void ax25_start_t3timer(ax25_cb *);
0464 void ax25_start_idletimer(ax25_cb *);
0465 void ax25_stop_heartbeat(ax25_cb *);
0466 void ax25_stop_t1timer(ax25_cb *);
0467 void ax25_stop_t2timer(ax25_cb *);
0468 void ax25_stop_t3timer(ax25_cb *);
0469 void ax25_stop_idletimer(ax25_cb *);
0470 int ax25_t1timer_running(ax25_cb *);
0471 unsigned long ax25_display_timer(struct timer_list *);
0472
0473
0474 extern int ax25_uid_policy;
0475 ax25_uid_assoc *ax25_findbyuid(kuid_t);
0476 int __must_check ax25_uid_ioctl(int, struct sockaddr_ax25 *);
0477 extern const struct seq_operations ax25_uid_seqops;
0478 void ax25_uid_free(void);
0479
0480
0481 #ifdef CONFIG_SYSCTL
0482 int ax25_register_dev_sysctl(ax25_dev *ax25_dev);
0483 void ax25_unregister_dev_sysctl(ax25_dev *ax25_dev);
0484 #else
0485 static inline int ax25_register_dev_sysctl(ax25_dev *ax25_dev) { return 0; }
0486 static inline void ax25_unregister_dev_sysctl(ax25_dev *ax25_dev) {}
0487 #endif
0488
0489 #endif