blob: 847a597ce97164456dc2f6f187410824b1b6a6f1 [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
Andreas Eversberg3744b872011-09-27 12:12:36 +020021extern const struct lapd_profile lapd_profile_isdn;
22extern const struct lapd_profile lapd_profile_abis;
23extern const struct lapd_profile lapd_profile_sat;
24
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +020025struct lapd_instance {
26 struct llist_head list; /* list of LAPD instances */
27 int network_side;
28
Andreas Eversberga7ff0012011-09-26 11:29:30 +020029 void (*transmit_cb)(struct msgb *msg, void *cbdata);
30 void *transmit_cbdata;
31 void (*receive_cb)(struct osmo_dlsap_prim *odp, uint8_t tei,
32 uint8_t sapi, void *rx_cbdata);
33 void *receive_cbdata;
34
Andreas Eversberg3744b872011-09-27 12:12:36 +020035 struct lapd_profile profile; /* must be a copy */
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +020036
37 struct llist_head tei_list; /* list of TEI in this LAPD instance */
38};
39
Pablo Neira Ayuso31fe5f22011-08-09 23:15:38 +020040enum lapd_recv_errors {
41 LAPD_ERR_NONE = 0,
42 LAPD_ERR_BAD_LEN,
43 LAPD_ERR_BAD_ADDR,
44 LAPD_ERR_UNKNOWN_S_CMD,
45 LAPD_ERR_UNKNOWN_U_CMD,
46 LAPD_ERR_UNKNOWN_TEI,
47 LAPD_ERR_BAD_CMD,
Andreas Eversberga7ff0012011-09-26 11:29:30 +020048 LAPD_ERR_NO_MEM,
Pablo Neira Ayuso31fe5f22011-08-09 23:15:38 +020049 __LAPD_ERR_MAX
50};
51
Andreas Eversberga7ff0012011-09-26 11:29:30 +020052int lapd_receive(struct lapd_instance *li, struct msgb *msg, int *error);
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +020053
Andreas Eversberga7ff0012011-09-26 11:29:30 +020054void lapd_transmit(struct lapd_instance *li, uint8_t tei, uint8_t sapi,
55 struct msgb *msg);
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +020056
57struct lapd_instance *lapd_instance_alloc(int network_side,
Andreas Eversberga7ff0012011-09-26 11:29:30 +020058 void (*tx_cb)(struct msgb *msg, void *cbdata), void *tx_cbdata,
59 void (*rx_cb)(struct osmo_dlsap_prim *odp, uint8_t tei, uint8_t sapi,
60 void *rx_cbdata), void *rx_cbdata,
Andreas Eversberg3744b872011-09-27 12:12:36 +020061 const struct lapd_profile *profile);
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +020062
Harald Welte14078ea2011-08-24 09:45:11 +020063void lapd_instance_free(struct lapd_instance *li);
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +020064
65/* Start a (user-side) SAP for the specified TEI/SAPI on the LAPD instance */
66int lapd_sap_start(struct lapd_instance *li, uint8_t tei, uint8_t sapi);
67
68/* Stop a (user-side) SAP for the specified TEI/SAPI on the LAPD instance */
69int lapd_sap_stop(struct lapd_instance *li, uint8_t tei, uint8_t sapi);
70
71#endif /* OPENBSC_LAPD_H */