Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 1 | #ifndef OPENBSC_LAPD_H |
| 2 | #define OPENBSC_LAPD_H |
| 3 | |
| 4 | #include <stdint.h> |
| 5 | |
| 6 | #include <osmocom/core/linuxlist.h> |
Andreas Eversberg | a7ff001 | 2011-09-26 11:29:30 +0200 | [diff] [blame] | 7 | #include <osmocom/gsm/lapd_core.h> |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 8 | |
Andreas Eversberg | 3744b87 | 2011-09-27 12:12:36 +0200 | [diff] [blame] | 9 | struct lapd_profile { |
Andreas Eversberg | 3c46044 | 2011-09-28 02:46:16 +0200 | [diff] [blame] | 10 | uint8_t k[64]; |
Andreas Eversberg | 3744b87 | 2011-09-27 12:12:36 +0200 | [diff] [blame] | 11 | 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 Eversberg | a7ff001 | 2011-09-26 11:29:30 +0200 | [diff] [blame] | 19 | }; |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 20 | |
Andreas Eversberg | 3744b87 | 2011-09-27 12:12:36 +0200 | [diff] [blame] | 21 | extern const struct lapd_profile lapd_profile_isdn; |
| 22 | extern const struct lapd_profile lapd_profile_abis; |
| 23 | extern const struct lapd_profile lapd_profile_sat; |
| 24 | |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 25 | struct lapd_instance { |
| 26 | struct llist_head list; /* list of LAPD instances */ |
| 27 | int network_side; |
| 28 | |
Andreas Eversberg | a7ff001 | 2011-09-26 11:29:30 +0200 | [diff] [blame] | 29 | 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 Eversberg | 3744b87 | 2011-09-27 12:12:36 +0200 | [diff] [blame] | 35 | struct lapd_profile profile; /* must be a copy */ |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 36 | |
| 37 | struct llist_head tei_list; /* list of TEI in this LAPD instance */ |
Pablo Neira Ayuso | 9530600 | 2012-08-22 16:43:59 +0200 | [diff] [blame] | 38 | int pcap_fd; /* PCAP file descriptor */ |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 39 | }; |
| 40 | |
Pablo Neira Ayuso | 31fe5f2 | 2011-08-09 23:15:38 +0200 | [diff] [blame] | 41 | enum 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 Eversberg | a7ff001 | 2011-09-26 11:29:30 +0200 | [diff] [blame] | 49 | LAPD_ERR_NO_MEM, |
Pablo Neira Ayuso | 31fe5f2 | 2011-08-09 23:15:38 +0200 | [diff] [blame] | 50 | __LAPD_ERR_MAX |
| 51 | }; |
| 52 | |
Alexander Huemer | 86fc3c8 | 2015-11-06 20:56:29 +0100 | [diff] [blame] | 53 | struct lapd_tei *lapd_tei_alloc(struct lapd_instance *li, uint8_t tei); |
| 54 | |
Andreas Eversberg | a7ff001 | 2011-09-26 11:29:30 +0200 | [diff] [blame] | 55 | int lapd_receive(struct lapd_instance *li, struct msgb *msg, int *error); |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 56 | |
Andreas Eversberg | a7ff001 | 2011-09-26 11:29:30 +0200 | [diff] [blame] | 57 | void lapd_transmit(struct lapd_instance *li, uint8_t tei, uint8_t sapi, |
| 58 | struct msgb *msg); |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 59 | |
| 60 | struct lapd_instance *lapd_instance_alloc(int network_side, |
Andreas Eversberg | a7ff001 | 2011-09-26 11:29:30 +0200 | [diff] [blame] | 61 | 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 Eversberg | 3744b87 | 2011-09-27 12:12:36 +0200 | [diff] [blame] | 64 | const struct lapd_profile *profile); |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 65 | |
Harald Welte | 14078ea | 2011-08-24 09:45:11 +0200 | [diff] [blame] | 66 | void lapd_instance_free(struct lapd_instance *li); |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 67 | |
| 68 | /* Start a (user-side) SAP for the specified TEI/SAPI on the LAPD instance */ |
| 69 | int 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 */ |
| 72 | int lapd_sap_stop(struct lapd_instance *li, uint8_t tei, uint8_t sapi); |
| 73 | |
| 74 | #endif /* OPENBSC_LAPD_H */ |