18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * see notice in l1oip.c
48c2ecf20Sopenharmony_ci */
58c2ecf20Sopenharmony_ci
68c2ecf20Sopenharmony_ci/* debugging */
78c2ecf20Sopenharmony_ci#define DEBUG_L1OIP_INIT	0x00010000
88c2ecf20Sopenharmony_ci#define DEBUG_L1OIP_SOCKET	0x00020000
98c2ecf20Sopenharmony_ci#define DEBUG_L1OIP_MGR		0x00040000
108c2ecf20Sopenharmony_ci#define DEBUG_L1OIP_MSG		0x00080000
118c2ecf20Sopenharmony_ci
128c2ecf20Sopenharmony_ci/* enable to disorder received bchannels by sequence 2143658798... */
138c2ecf20Sopenharmony_ci/*
148c2ecf20Sopenharmony_ci  #define REORDER_DEBUG
158c2ecf20Sopenharmony_ci*/
168c2ecf20Sopenharmony_ci
178c2ecf20Sopenharmony_ci/* frames */
188c2ecf20Sopenharmony_ci#define L1OIP_MAX_LEN		2048		/* max packet size form l2 */
198c2ecf20Sopenharmony_ci#define L1OIP_MAX_PERFRAME	1400		/* max data size in one frame */
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_ci
228c2ecf20Sopenharmony_ci/* timers */
238c2ecf20Sopenharmony_ci#define L1OIP_KEEPALIVE		15
248c2ecf20Sopenharmony_ci#define L1OIP_TIMEOUT		65
258c2ecf20Sopenharmony_ci
268c2ecf20Sopenharmony_ci
278c2ecf20Sopenharmony_ci/* socket */
288c2ecf20Sopenharmony_ci#define L1OIP_DEFAULTPORT	931
298c2ecf20Sopenharmony_ci
308c2ecf20Sopenharmony_ci
318c2ecf20Sopenharmony_ci/* channel structure */
328c2ecf20Sopenharmony_cistruct l1oip_chan {
338c2ecf20Sopenharmony_ci	struct dchannel		*dch;
348c2ecf20Sopenharmony_ci	struct bchannel		*bch;
358c2ecf20Sopenharmony_ci	u32			tx_counter;	/* counts xmit bytes/packets */
368c2ecf20Sopenharmony_ci	u32			rx_counter;	/* counts recv bytes/packets */
378c2ecf20Sopenharmony_ci	u32			codecstate;	/* used by codec to save data */
388c2ecf20Sopenharmony_ci#ifdef REORDER_DEBUG
398c2ecf20Sopenharmony_ci	int			disorder_flag;
408c2ecf20Sopenharmony_ci	struct sk_buff		*disorder_skb;
418c2ecf20Sopenharmony_ci	u32			disorder_cnt;
428c2ecf20Sopenharmony_ci#endif
438c2ecf20Sopenharmony_ci};
448c2ecf20Sopenharmony_ci
458c2ecf20Sopenharmony_ci
468c2ecf20Sopenharmony_ci/* card structure */
478c2ecf20Sopenharmony_cistruct l1oip {
488c2ecf20Sopenharmony_ci	struct list_head        list;
498c2ecf20Sopenharmony_ci
508c2ecf20Sopenharmony_ci	/* card */
518c2ecf20Sopenharmony_ci	int			registered;	/* if registered with mISDN */
528c2ecf20Sopenharmony_ci	char			name[MISDN_MAX_IDLEN];
538c2ecf20Sopenharmony_ci	int			idx;		/* card index */
548c2ecf20Sopenharmony_ci	int			pri;		/* 1=pri, 0=bri */
558c2ecf20Sopenharmony_ci	int			d_idx;		/* current dchannel number */
568c2ecf20Sopenharmony_ci	int			b_num;		/* number of bchannels */
578c2ecf20Sopenharmony_ci	u32			id;		/* id of connection */
588c2ecf20Sopenharmony_ci	int			ondemand;	/* if transmis. is on demand */
598c2ecf20Sopenharmony_ci	int			bundle;		/* bundle channels in one frm */
608c2ecf20Sopenharmony_ci	int			codec;		/* codec to use for transmis. */
618c2ecf20Sopenharmony_ci	int			limit;		/* limit number of bchannels */
628c2ecf20Sopenharmony_ci	bool			shutdown;	/* if card is released */
638c2ecf20Sopenharmony_ci
648c2ecf20Sopenharmony_ci	/* timer */
658c2ecf20Sopenharmony_ci	struct timer_list	keep_tl;
668c2ecf20Sopenharmony_ci	struct timer_list	timeout_tl;
678c2ecf20Sopenharmony_ci	int			timeout_on;
688c2ecf20Sopenharmony_ci	struct work_struct	workq;
698c2ecf20Sopenharmony_ci
708c2ecf20Sopenharmony_ci	/* socket */
718c2ecf20Sopenharmony_ci	struct socket		*socket;	/* if set, socket is created */
728c2ecf20Sopenharmony_ci	struct completion	socket_complete;/* completion of sock thread */
738c2ecf20Sopenharmony_ci	struct task_struct	*socket_thread;
748c2ecf20Sopenharmony_ci	spinlock_t		socket_lock;	/* access sock outside thread */
758c2ecf20Sopenharmony_ci	u32			remoteip;	/* if all set, ip is assigned */
768c2ecf20Sopenharmony_ci	u16			localport;	/* must always be set */
778c2ecf20Sopenharmony_ci	u16			remoteport;	/* must always be set */
788c2ecf20Sopenharmony_ci	struct sockaddr_in	sin_local;	/* local socket name */
798c2ecf20Sopenharmony_ci	struct sockaddr_in	sin_remote;	/* remote socket name */
808c2ecf20Sopenharmony_ci	struct msghdr		sendmsg;	/* ip message to send */
818c2ecf20Sopenharmony_ci	struct kvec		sendiov;	/* iov for message */
828c2ecf20Sopenharmony_ci
838c2ecf20Sopenharmony_ci	/* frame */
848c2ecf20Sopenharmony_ci	struct l1oip_chan	chan[128];	/* channel instances */
858c2ecf20Sopenharmony_ci};
868c2ecf20Sopenharmony_ci
878c2ecf20Sopenharmony_ciextern int l1oip_law_to_4bit(u8 *data, int len, u8 *result, u32 *state);
888c2ecf20Sopenharmony_ciextern int l1oip_4bit_to_law(u8 *data, int len, u8 *result);
898c2ecf20Sopenharmony_ciextern int l1oip_alaw_to_ulaw(u8 *data, int len, u8 *result);
908c2ecf20Sopenharmony_ciextern int l1oip_ulaw_to_alaw(u8 *data, int len, u8 *result);
918c2ecf20Sopenharmony_ciextern void l1oip_4bit_free(void);
928c2ecf20Sopenharmony_ciextern int l1oip_4bit_alloc(int ulaw);
93