blob: 1e9ffe7e2e1272fe67c46c0558dce498edf4747e [file] [log] [blame]
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +02001#ifndef OPENBSC_LAPD_H
2#define OPENBSC_LAPD_H
3
4#include <stdint.h>
5
6#include <osmocom/core/linuxlist.h>
Andreas Eversberga7ff0012011-09-26 11:29:30 +02007#include <osmocom/gsm/lapd_core.h>
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +02008
Andreas Eversberg3744b872011-09-27 12:12:36 +02009struct lapd_profile {
Andreas Eversberg3c460442011-09-28 02:46:16 +020010 uint8_t k[64];
Andreas Eversberg3744b872011-09-27 12:12:36 +020011 int n200;
12 int n201;
13 int n202;
14 int t200_sec, t200_usec;
15 int t201_sec, t201_usec;
16 int t202_sec, t202_usec;
17 int t203_sec, t203_usec;
18 int short_address;
Andreas Eversberga7ff0012011-09-26 11:29:30 +020019};
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +020020
Philipp0c7d5f42016-10-19 18:38:58 +020021/* predefined lapd profiles (see lapd.c for definition) */
Andreas Eversberg3744b872011-09-27 12:12:36 +020022extern const struct lapd_profile lapd_profile_isdn;
23extern const struct lapd_profile lapd_profile_abis;
Philipp0c7d5f42016-10-19 18:38:58 +020024extern const struct lapd_profile lapd_profile_abis_ericsson;
Andreas Eversberg3744b872011-09-27 12:12:36 +020025extern const struct lapd_profile lapd_profile_sat;
26
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +020027struct lapd_instance {
28 struct llist_head list; /* list of LAPD instances */
29 int network_side;
30
Andreas Eversberga7ff0012011-09-26 11:29:30 +020031 void (*transmit_cb)(struct msgb *msg, void *cbdata);
32 void *transmit_cbdata;
33 void (*receive_cb)(struct osmo_dlsap_prim *odp, uint8_t tei,
34 uint8_t sapi, void *rx_cbdata);
35 void *receive_cbdata;
36
Andreas Eversberg3744b872011-09-27 12:12:36 +020037 struct lapd_profile profile; /* must be a copy */
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +020038
39 struct llist_head tei_list; /* list of TEI in this LAPD instance */
Pablo Neira Ayuso95306002012-08-22 16:43:59 +020040 int pcap_fd; /* PCAP file descriptor */
Harald Welteb9031882020-05-02 21:09:15 +020041 char *name; /* human-readable name */
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +020042};
43
Pablo Neira Ayuso31fe5f22011-08-09 23:15:38 +020044enum lapd_recv_errors {
45 LAPD_ERR_NONE = 0,
46 LAPD_ERR_BAD_LEN,
47 LAPD_ERR_BAD_ADDR,
48 LAPD_ERR_UNKNOWN_S_CMD,
49 LAPD_ERR_UNKNOWN_U_CMD,
50 LAPD_ERR_UNKNOWN_TEI,
51 LAPD_ERR_BAD_CMD,
Andreas Eversberga7ff0012011-09-26 11:29:30 +020052 LAPD_ERR_NO_MEM,
Pablo Neira Ayuso31fe5f22011-08-09 23:15:38 +020053 __LAPD_ERR_MAX
54};
55
Alexander Huemer86fc3c82015-11-06 20:56:29 +010056struct lapd_tei *lapd_tei_alloc(struct lapd_instance *li, uint8_t tei);
57
Andreas Eversberga7ff0012011-09-26 11:29:30 +020058int lapd_receive(struct lapd_instance *li, struct msgb *msg, int *error);
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +020059
Andreas Eversberga7ff0012011-09-26 11:29:30 +020060void lapd_transmit(struct lapd_instance *li, uint8_t tei, uint8_t sapi,
61 struct msgb *msg);
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +020062
63struct lapd_instance *lapd_instance_alloc(int network_side,
Andreas Eversberga7ff0012011-09-26 11:29:30 +020064 void (*tx_cb)(struct msgb *msg, void *cbdata), void *tx_cbdata,
65 void (*rx_cb)(struct osmo_dlsap_prim *odp, uint8_t tei, uint8_t sapi,
66 void *rx_cbdata), void *rx_cbdata,
Harald Welteb9031882020-05-02 21:09:15 +020067 const struct lapd_profile *profile)
68OSMO_DEPRECATED("Use lapd_instance_alloc2() instead");
69
70struct lapd_instance *lapd_instance_alloc2(int network_side,
71 void (*tx_cb)(struct msgb *msg, void *cbdata), void *tx_cbdata,
72 void (*rx_cb)(struct osmo_dlsap_prim *odp, uint8_t tei, uint8_t sapi,
73 void *rx_cbdata), void *rx_cbdata,
74 const struct lapd_profile *profile, const char *name);
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +020075
Philipp0c7d5f42016-10-19 18:38:58 +020076/* In rare cases (e.g. Ericsson's lapd dialect), it may be necessary to
77 * exchange the lapd profile on the fly. lapd_instance_set_profile()
78 * allwos to set the lapd profile on a lapd instance danymically to
79 * one of the lapd profiles define above. */
80void lapd_instance_set_profile(struct lapd_instance *li,
81 const struct lapd_profile *profile);
82
Harald Welte14078ea2011-08-24 09:45:11 +020083void lapd_instance_free(struct lapd_instance *li);
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +020084
85/* Start a (user-side) SAP for the specified TEI/SAPI on the LAPD instance */
86int lapd_sap_start(struct lapd_instance *li, uint8_t tei, uint8_t sapi);
87
88/* Stop a (user-side) SAP for the specified TEI/SAPI on the LAPD instance */
89int lapd_sap_stop(struct lapd_instance *li, uint8_t tei, uint8_t sapi);
90
91#endif /* OPENBSC_LAPD_H */