Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 1 | /* gprs_rlcmac.cpp |
| 2 | * |
| 3 | * Copyright (C) 2012 Ivan Klyuchnikov |
Andreas Eversberg | 5dac2f0 | 2012-06-27 15:52:04 +0200 | [diff] [blame] | 4 | * Copyright (C) 2012 Andreas Eversberg <jolly@eversberg.eu> |
Holger Hans Peter Freyther | d6bd91e | 2013-08-24 21:16:55 +0200 | [diff] [blame] | 5 | * Copyright (C) 2013 by Holger Hans Peter Freyther |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 6 | * |
| 7 | * This program is free software; you can redistribute it and/or |
| 8 | * modify it under the terms of the GNU General Public License |
| 9 | * as published by the Free Software Foundation; either version 2 |
| 10 | * of the License, or (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 |
| 18 | * along with this program; if not, write to the Free Software |
| 19 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 20 | */ |
| 21 | |
| 22 | #include <gprs_bssgp_pcu.h> |
| 23 | #include <pcu_l1_if.h> |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 24 | #include <gprs_rlcmac.h> |
Holger Hans Peter Freyther | 67ed34e | 2013-10-17 17:01:54 +0200 | [diff] [blame] | 25 | #include <bts.h> |
Holger Hans Peter Freyther | 63f29d6 | 2013-10-19 19:04:03 +0200 | [diff] [blame] | 26 | #include <encoding.h> |
Holger Hans Peter Freyther | 099535a | 2013-10-16 17:42:31 +0200 | [diff] [blame] | 27 | #include <tbf.h> |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 28 | |
Andreas Eversberg | 53f4725 | 2012-07-15 07:10:10 +0200 | [diff] [blame] | 29 | |
Andreas Eversberg | 6681bb8 | 2012-07-25 08:48:44 +0200 | [diff] [blame] | 30 | extern void *tall_pcu_ctx; |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 31 | |
Andreas Eversberg | b83e2a7 | 2012-10-07 15:26:00 +0200 | [diff] [blame] | 32 | #ifdef DEBUG_DIAGRAM |
| 33 | struct timeval diagram_time = {0,0}; |
| 34 | struct timeval diagram_last_tv = {0,0}; |
| 35 | |
Holger Hans Peter Freyther | 34bd8bd | 2013-10-19 21:10:38 +0200 | [diff] [blame] | 36 | void debug_diagram(BTS *bts, int diag, const char *format, ...) |
Andreas Eversberg | b83e2a7 | 2012-10-07 15:26:00 +0200 | [diff] [blame] | 37 | { |
| 38 | va_list ap; |
| 39 | char debug[128]; |
| 40 | char line[1024]; |
| 41 | struct gprs_rlcmac_tbf *tbf, *tbf_a[16]; |
| 42 | int max_diag = -1, i; |
| 43 | uint64_t diff = 0; |
| 44 | |
| 45 | va_start(ap, format); |
| 46 | vsnprintf(debug, sizeof(debug) - 1, format, ap); |
| 47 | debug[19] = ' '; |
| 48 | debug[20] = '\0'; |
| 49 | va_end(ap); |
| 50 | |
| 51 | memset(tbf_a, 0, sizeof(tbf_a)); |
Holger Hans Peter Freyther | 34bd8bd | 2013-10-19 21:10:38 +0200 | [diff] [blame] | 52 | llist_for_each_entry(tbf, &bts->bts_data()->ul_tbfs, list) { |
Andreas Eversberg | b83e2a7 | 2012-10-07 15:26:00 +0200 | [diff] [blame] | 53 | if (tbf->diag < 16) { |
| 54 | if (tbf->diag > max_diag) |
| 55 | max_diag = tbf->diag; |
| 56 | tbf_a[tbf->diag] = tbf; |
| 57 | } |
| 58 | } |
Holger Hans Peter Freyther | 34bd8bd | 2013-10-19 21:10:38 +0200 | [diff] [blame] | 59 | llist_for_each_entry(tbf, &bts->bts_data()->dl_tbfs, list) { |
Andreas Eversberg | b83e2a7 | 2012-10-07 15:26:00 +0200 | [diff] [blame] | 60 | if (tbf->diag < 16) { |
| 61 | if (tbf->diag > max_diag) |
| 62 | max_diag = tbf->diag; |
| 63 | tbf_a[tbf->diag] = tbf; |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | if (diagram_last_tv.tv_sec) { |
| 68 | diff = (uint64_t)(diagram_time.tv_sec - |
| 69 | diagram_last_tv.tv_sec) * 1000; |
| 70 | diff += diagram_time.tv_usec / 1000; |
| 71 | diff -= diagram_last_tv.tv_usec / 1000; |
| 72 | } |
| 73 | memcpy(&diagram_last_tv, &diagram_time, sizeof(struct timeval)); |
| 74 | |
| 75 | if (diff > 0) { |
| 76 | if (diff > 99999) |
| 77 | strcpy(line, " ... : "); |
| 78 | else |
| 79 | sprintf(line, "%3d.%03d: ", (int)(diff / 1000), |
| 80 | (int)(diff % 1000)); |
| 81 | for (i = 0; i <= max_diag; i++) { |
| 82 | if (tbf_a[i] == NULL) { |
| 83 | strcat(line, " "); |
| 84 | continue; |
| 85 | } |
| 86 | if (tbf_a[i]->diag_new) { |
| 87 | strcat(line, " | "); |
| 88 | continue; |
| 89 | } |
| 90 | strcat(line, " "); |
| 91 | } |
| 92 | puts(line); |
| 93 | } |
| 94 | strcpy(line, " : "); |
| 95 | for (i = 0; i <= max_diag; i++) { |
| 96 | if (tbf_a[i] == NULL) { |
| 97 | strcat(line, " "); |
| 98 | continue; |
| 99 | } |
| 100 | if (tbf_a[i]->diag != diag) { |
| 101 | strcat(line, " | "); |
| 102 | continue; |
| 103 | } |
| 104 | if (strlen(debug) < 19) { |
| 105 | strcat(line, " "); |
| 106 | memcpy(line + strlen(line) - 11 - strlen(debug) / 2, |
| 107 | debug, strlen(debug)); |
| 108 | } else |
| 109 | strcat(line, debug); |
| 110 | tbf_a[i]->diag_new = 1; |
| 111 | } |
| 112 | puts(line); |
| 113 | } |
| 114 | #endif |
| 115 | |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 116 | /* Send Uplink unit-data to SGSN. */ |
Andreas Eversberg | 3e372d5 | 2012-07-06 09:28:15 +0200 | [diff] [blame] | 117 | int gprs_rlcmac_tx_ul_ud(gprs_rlcmac_tbf *tbf) |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 118 | { |
Andreas Eversberg | 9a91346 | 2012-09-23 06:42:38 +0200 | [diff] [blame] | 119 | uint8_t qos_profile[3]; |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 120 | struct msgb *llc_pdu; |
Andreas Eversberg | 5dac2f0 | 2012-06-27 15:52:04 +0200 | [diff] [blame] | 121 | unsigned msg_len = NS_HDR_LEN + BSSGP_HDR_LEN + tbf->llc_index; |
Holger Hans Peter Freyther | 90692f9 | 2013-07-13 12:51:16 +0200 | [diff] [blame] | 122 | struct bssgp_bvc_ctx *bctx = gprs_bssgp_pcu_current_bctx(); |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 123 | |
Andreas Eversberg | b0c7ea7 | 2012-07-13 14:46:03 +0200 | [diff] [blame] | 124 | LOGP(DBSSGP, LOGL_INFO, "LLC [PCU -> SGSN] TFI: %u TLLI: 0x%08x len=%d\n", tbf->tfi, tbf->tlli, tbf->llc_index); |
Andreas Eversberg | 3e372d5 | 2012-07-06 09:28:15 +0200 | [diff] [blame] | 125 | if (!bctx) { |
| 126 | LOGP(DBSSGP, LOGL_ERROR, "No bctx\n"); |
| 127 | return -EIO; |
| 128 | } |
Ivan Kluchnikov | c320d86 | 2012-03-18 15:04:48 +0400 | [diff] [blame] | 129 | |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 130 | llc_pdu = msgb_alloc_headroom(msg_len, msg_len,"llc_pdu"); |
Andreas Eversberg | 9a91346 | 2012-09-23 06:42:38 +0200 | [diff] [blame] | 131 | uint8_t *buf = msgb_push(llc_pdu, TL16V_GROSS_LEN(sizeof(uint8_t)*tbf->llc_index)); |
| 132 | tl16v_put(buf, BSSGP_IE_LLC_PDU, sizeof(uint8_t)*tbf->llc_index, tbf->llc_frame); |
| 133 | qos_profile[0] = QOS_PROFILE >> 16; |
| 134 | qos_profile[1] = QOS_PROFILE >> 8; |
| 135 | qos_profile[2] = QOS_PROFILE; |
| 136 | bssgp_tx_ul_ud(bctx, tbf->tlli, qos_profile, llc_pdu); |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 137 | |
Andreas Eversberg | 3e372d5 | 2012-07-06 09:28:15 +0200 | [diff] [blame] | 138 | return 0; |
Ivan Kluchnikov | c7e7f68 | 2012-06-29 22:53:15 +0400 | [diff] [blame] | 139 | } |
Andreas Eversberg | 8c3680d | 2012-10-08 12:30:56 +0200 | [diff] [blame] | 140 | |
| 141 | int gprs_rlcmac_paging_request(uint8_t *ptmsi, uint16_t ptmsi_len, |
| 142 | const char *imsi) |
| 143 | { |
| 144 | LOGP(DRLCMAC, LOGL_NOTICE, "TX: [PCU -> BTS] Paging Request (CCCH)\n"); |
| 145 | bitvec *paging_request = bitvec_alloc(23); |
| 146 | bitvec_unhex(paging_request, "2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b"); |
Holger Hans Peter Freyther | 63f29d6 | 2013-10-19 19:04:03 +0200 | [diff] [blame] | 147 | int plen = Encoding::write_paging_request(paging_request, ptmsi, ptmsi_len); |
Andreas Eversberg | 8c3680d | 2012-10-08 12:30:56 +0200 | [diff] [blame] | 148 | pcu_l1if_tx_pch(paging_request, plen, (char *)imsi); |
| 149 | bitvec_free(paging_request); |
| 150 | |
| 151 | return 0; |
| 152 | } |
Andreas Eversberg | a004e6a | 2013-05-13 16:45:21 +0200 | [diff] [blame] | 153 | |
| 154 | |