18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Layer 2 defines
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * Copyright 2008  by Karsten Keil <kkeil@novell.com>
68c2ecf20Sopenharmony_ci */
78c2ecf20Sopenharmony_ci
88c2ecf20Sopenharmony_ci#include <linux/mISDNif.h>
98c2ecf20Sopenharmony_ci#include <linux/skbuff.h>
108c2ecf20Sopenharmony_ci#include "fsm.h"
118c2ecf20Sopenharmony_ci
128c2ecf20Sopenharmony_ci#define MAX_WINDOW	8
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_cistruct manager {
158c2ecf20Sopenharmony_ci	struct mISDNchannel	ch;
168c2ecf20Sopenharmony_ci	struct mISDNchannel	bcast;
178c2ecf20Sopenharmony_ci	u_long			options;
188c2ecf20Sopenharmony_ci	struct list_head	layer2;
198c2ecf20Sopenharmony_ci	rwlock_t		lock;
208c2ecf20Sopenharmony_ci	struct FsmInst		deact;
218c2ecf20Sopenharmony_ci	struct FsmTimer		datimer;
228c2ecf20Sopenharmony_ci	struct sk_buff_head	sendq;
238c2ecf20Sopenharmony_ci	struct mISDNchannel	*up;
248c2ecf20Sopenharmony_ci	u_int			nextid;
258c2ecf20Sopenharmony_ci	u_int			lastid;
268c2ecf20Sopenharmony_ci};
278c2ecf20Sopenharmony_ci
288c2ecf20Sopenharmony_cistruct teimgr {
298c2ecf20Sopenharmony_ci	int			ri;
308c2ecf20Sopenharmony_ci	int			rcnt;
318c2ecf20Sopenharmony_ci	struct FsmInst		tei_m;
328c2ecf20Sopenharmony_ci	struct FsmTimer		timer;
338c2ecf20Sopenharmony_ci	int			tval, nval;
348c2ecf20Sopenharmony_ci	struct layer2		*l2;
358c2ecf20Sopenharmony_ci	struct manager		*mgr;
368c2ecf20Sopenharmony_ci};
378c2ecf20Sopenharmony_ci
388c2ecf20Sopenharmony_cistruct laddr {
398c2ecf20Sopenharmony_ci	u_char	A;
408c2ecf20Sopenharmony_ci	u_char	B;
418c2ecf20Sopenharmony_ci};
428c2ecf20Sopenharmony_ci
438c2ecf20Sopenharmony_cistruct layer2 {
448c2ecf20Sopenharmony_ci	struct list_head	list;
458c2ecf20Sopenharmony_ci	struct mISDNchannel	ch;
468c2ecf20Sopenharmony_ci	u_long			flag;
478c2ecf20Sopenharmony_ci	int			id;
488c2ecf20Sopenharmony_ci	struct mISDNchannel	*up;
498c2ecf20Sopenharmony_ci	signed char		sapi;
508c2ecf20Sopenharmony_ci	signed char		tei;
518c2ecf20Sopenharmony_ci	struct laddr		addr;
528c2ecf20Sopenharmony_ci	u_int			maxlen;
538c2ecf20Sopenharmony_ci	struct teimgr		*tm;
548c2ecf20Sopenharmony_ci	u_int			vs, va, vr;
558c2ecf20Sopenharmony_ci	int			rc;
568c2ecf20Sopenharmony_ci	u_int			window;
578c2ecf20Sopenharmony_ci	u_int			sow;
588c2ecf20Sopenharmony_ci	struct FsmInst		l2m;
598c2ecf20Sopenharmony_ci	struct FsmTimer		t200, t203;
608c2ecf20Sopenharmony_ci	int			T200, N200, T203;
618c2ecf20Sopenharmony_ci	u_int			next_id;
628c2ecf20Sopenharmony_ci	u_int			down_id;
638c2ecf20Sopenharmony_ci	struct sk_buff		*windowar[MAX_WINDOW];
648c2ecf20Sopenharmony_ci	struct sk_buff_head	i_queue;
658c2ecf20Sopenharmony_ci	struct sk_buff_head	ui_queue;
668c2ecf20Sopenharmony_ci	struct sk_buff_head	down_queue;
678c2ecf20Sopenharmony_ci	struct sk_buff_head	tmp_queue;
688c2ecf20Sopenharmony_ci};
698c2ecf20Sopenharmony_ci
708c2ecf20Sopenharmony_cienum {
718c2ecf20Sopenharmony_ci	ST_L2_1,
728c2ecf20Sopenharmony_ci	ST_L2_2,
738c2ecf20Sopenharmony_ci	ST_L2_3,
748c2ecf20Sopenharmony_ci	ST_L2_4,
758c2ecf20Sopenharmony_ci	ST_L2_5,
768c2ecf20Sopenharmony_ci	ST_L2_6,
778c2ecf20Sopenharmony_ci	ST_L2_7,
788c2ecf20Sopenharmony_ci	ST_L2_8,
798c2ecf20Sopenharmony_ci};
808c2ecf20Sopenharmony_ci
818c2ecf20Sopenharmony_ci#define L2_STATE_COUNT (ST_L2_8 + 1)
828c2ecf20Sopenharmony_ci
838c2ecf20Sopenharmony_ciextern struct layer2	*create_l2(struct mISDNchannel *, u_int,
848c2ecf20Sopenharmony_ci				   u_long, int, int);
858c2ecf20Sopenharmony_ciextern int		tei_l2(struct layer2 *, u_int, u_long arg);
868c2ecf20Sopenharmony_ci
878c2ecf20Sopenharmony_ci
888c2ecf20Sopenharmony_ci/* from tei.c */
898c2ecf20Sopenharmony_ciextern int		l2_tei(struct layer2 *, u_int, u_long arg);
908c2ecf20Sopenharmony_ciextern void		TEIrelease(struct layer2 *);
918c2ecf20Sopenharmony_ciextern int		TEIInit(u_int *);
928c2ecf20Sopenharmony_ciextern void		TEIFree(void);
938c2ecf20Sopenharmony_ci
948c2ecf20Sopenharmony_ci#define MAX_L2HEADER_LEN 4
958c2ecf20Sopenharmony_ci
968c2ecf20Sopenharmony_ci#define RR	0x01
978c2ecf20Sopenharmony_ci#define RNR	0x05
988c2ecf20Sopenharmony_ci#define REJ	0x09
998c2ecf20Sopenharmony_ci#define SABME	0x6f
1008c2ecf20Sopenharmony_ci#define SABM	0x2f
1018c2ecf20Sopenharmony_ci#define DM	0x0f
1028c2ecf20Sopenharmony_ci#define UI	0x03
1038c2ecf20Sopenharmony_ci#define DISC	0x43
1048c2ecf20Sopenharmony_ci#define UA	0x63
1058c2ecf20Sopenharmony_ci#define FRMR	0x87
1068c2ecf20Sopenharmony_ci#define XID	0xaf
1078c2ecf20Sopenharmony_ci
1088c2ecf20Sopenharmony_ci#define CMD	0
1098c2ecf20Sopenharmony_ci#define RSP	1
1108c2ecf20Sopenharmony_ci
1118c2ecf20Sopenharmony_ci#define LC_FLUSH_WAIT 1
1128c2ecf20Sopenharmony_ci
1138c2ecf20Sopenharmony_ci#define FLG_LAPB	0
1148c2ecf20Sopenharmony_ci#define FLG_LAPD	1
1158c2ecf20Sopenharmony_ci#define FLG_ORIG	2
1168c2ecf20Sopenharmony_ci#define FLG_MOD128	3
1178c2ecf20Sopenharmony_ci#define FLG_PEND_REL	4
1188c2ecf20Sopenharmony_ci#define FLG_L3_INIT	5
1198c2ecf20Sopenharmony_ci#define FLG_T200_RUN	6
1208c2ecf20Sopenharmony_ci#define FLG_ACK_PEND	7
1218c2ecf20Sopenharmony_ci#define FLG_REJEXC	8
1228c2ecf20Sopenharmony_ci#define FLG_OWN_BUSY	9
1238c2ecf20Sopenharmony_ci#define FLG_PEER_BUSY	10
1248c2ecf20Sopenharmony_ci#define FLG_DCHAN_BUSY	11
1258c2ecf20Sopenharmony_ci#define FLG_L1_ACTIV	12
1268c2ecf20Sopenharmony_ci#define FLG_ESTAB_PEND	13
1278c2ecf20Sopenharmony_ci#define FLG_PTP		14
1288c2ecf20Sopenharmony_ci#define FLG_FIXED_TEI	15
1298c2ecf20Sopenharmony_ci#define FLG_L2BLOCK	16
1308c2ecf20Sopenharmony_ci#define FLG_L1_NOTREADY	17
1318c2ecf20Sopenharmony_ci#define FLG_LAPD_NET	18
132