Initial import of OsmocomBB into git repository
[osmocom-bb.git] / src / target / firmware / layer1 / l23_api.c
1 /* Synchronous part of GSM Layer 1: API to Layer2+ */
2
3 /* (C) 2010 by Holger Hans Peter Freyther <zecke@selfish.org>
4  *
5  * All Rights Reserved
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along
18  * with this program; if not, write to the Free Software Foundation, Inc.,
19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20  *
21  */
22
23 #include <stdint.h>
24 #include <stdio.h>
25
26 #include <comm/msgb.h>
27 #include <comm/sercomm.h>
28
29 #include <layer1/sync.h>
30 #include <l1a_l23_interface.h>
31
32 /* the size we will allocate struct msgb* for HDLC */
33 #define L3_MSG_SIZE (sizeof(struct l1_ccch_info_ind) + 4)
34 #define L3_MSG_HEAD 4
35
36 void l1_queue_for_l2(struct msgb *msg)
37 {
38         /* forward via serial for now */
39         sercomm_sendmsg(SC_DLCI_L1A_L23, msg);
40 }
41
42 struct msgb *l1_create_l2_msg(int msg_type, uint32_t fn, uint16_t snr)
43 {
44         struct l1_info_dl *dl;
45         struct msgb *msg;
46
47         msg = msgb_alloc_headroom(L3_MSG_SIZE, L3_MSG_HEAD, "l1_burst");
48         if (!msg) {
49                 while (1) {
50                         puts("OOPS. Out of buffers...\n");
51                 }
52
53                 return NULL;
54         }
55
56         dl = (struct l1_info_dl *) msgb_put(msg, sizeof(*dl));
57         dl->msg_type = msg_type;
58         /* FIXME: we may want to compute T1/T2/T3 in L23 */
59         gsm_fn2gsmtime(&dl->time, fn);
60         dl->snr[0] = snr;
61
62         return msg;
63 }