blob: 29876339e35415e7424fac1ec53979014368b8ef [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 */
Pablo Neira Ayuso95306002012-08-22 16:43:59 +020038 int pcap_fd; /* PCAP file descriptor */
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +020039};
40
Pablo Neira Ayuso31fe5f22011-08-09 23:15:38 +020041enum lapd_recv_errors {
42 LAPD_ERR_NONE = 0,
43 LAPD_ERR_BAD_LEN,
44 LAPD_ERR_BAD_ADDR,
45 LAPD_ERR_UNKNOWN_S_CMD,
46 LAPD_ERR_UNKNOWN_U_CMD,
47 LAPD_ERR_UNKNOWN_TEI,
48 LAPD_ERR_BAD_CMD,
Andreas Eversberga7ff0012011-09-26 11:29:30 +020049 LAPD_ERR_NO_MEM,
Pablo Neira Ayuso31fe5f22011-08-09 23:15:38 +020050 __LAPD_ERR_MAX
51};
52
Alexander Huemer86fc3c82015-11-06 20:56:29 +010053struct lapd_tei *lapd_tei_alloc(struct lapd_instance *li, uint8_t tei);
54
Andreas Eversberga7ff0012011-09-26 11:29:30 +020055int lapd_receive(struct lapd_instance *li, struct msgb *msg, int *error);
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +020056
Andreas Eversberga7ff0012011-09-26 11:29:30 +020057void lapd_transmit(struct lapd_instance *li, uint8_t tei, uint8_t sapi,
58 struct msgb *msg);
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +020059
60struct lapd_instance *lapd_instance_alloc(int network_side,
Andreas Eversberga7ff0012011-09-26 11:29:30 +020061 void (*tx_cb)(struct msgb *msg, void *cbdata), void *tx_cbdata,
62 void (*rx_cb)(struct osmo_dlsap_prim *odp, uint8_t tei, uint8_t sapi,
63 void *rx_cbdata), void *rx_cbdata,
Andreas Eversberg3744b872011-09-27 12:12:36 +020064 const struct lapd_profile *profile);
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +020065
Harald Welte14078ea2011-08-24 09:45:11 +020066void lapd_instance_free(struct lapd_instance *li);
Pablo Neira Ayuso0ba77d52011-06-05 18:32:44 +020067
68/* Start a (user-side) SAP for the specified TEI/SAPI on the LAPD instance */
69int lapd_sap_start(struct lapd_instance *li, uint8_t tei, uint8_t sapi);
70
71/* Stop a (user-side) SAP for the specified TEI/SAPI on the LAPD instance */
72int lapd_sap_stop(struct lapd_instance *li, uint8_t tei, uint8_t sapi);
73
74#endif /* OPENBSC_LAPD_H */