Harald Welte | b68899d | 2009-01-06 21:47:18 +0000 | [diff] [blame] | 1 | /* Paging helper and manager.... */ |
| 2 | /* (C) 2009 by Holger Hans Peter Freyther <zecke@selfish.org> |
| 3 | * All Rights Reserved |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation; either version 2 of the License, or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License along |
| 16 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 18 | * |
| 19 | */ |
| 20 | |
| 21 | /* |
| 22 | * Relevant specs: |
| 23 | * 12.21: |
| 24 | * - 9.4.12 for CCCH Local Threshold |
| 25 | * |
| 26 | * 05.58: |
| 27 | * - 8.5.2 CCCH Load indication |
| 28 | * - 9.3.15 Paging Load |
| 29 | * |
| 30 | * Approach: |
| 31 | * - Send paging command to subscriber |
| 32 | * - On Channel Request we will remember the reason |
| 33 | * - After the ACK we will request the identity |
| 34 | * - Then we will send assign the gsm_subscriber and |
| 35 | * - and call a callback |
| 36 | */ |
| 37 | |
Harald Welte | 2f1311b | 2009-01-06 23:50:39 +0000 | [diff] [blame] | 38 | #include <stdio.h> |
| 39 | #include <stdlib.h> |
| 40 | |
Harald Welte | b68899d | 2009-01-06 21:47:18 +0000 | [diff] [blame] | 41 | #include <openbsc/paging.h> |
| 42 | #include <openbsc/debug.h> |
Harald Welte | 2f1311b | 2009-01-06 23:50:39 +0000 | [diff] [blame] | 43 | #include <openbsc/abis_rsl.h> |
| 44 | #include <openbsc/gsm_04_08.h> |
Harald Welte | b68899d | 2009-01-06 21:47:18 +0000 | [diff] [blame] | 45 | |
Harald Welte | 38c2f13 | 2009-01-06 23:10:57 +0000 | [diff] [blame] | 46 | #define PAGING_TIMEOUT 0, 5000 |
| 47 | |
Harald Welte | b68899d | 2009-01-06 21:47:18 +0000 | [diff] [blame] | 48 | static LLIST_HEAD(managed_bts); |
| 49 | |
Harald Welte | 38c2f13 | 2009-01-06 23:10:57 +0000 | [diff] [blame] | 50 | /* |
| 51 | * Kill one paging request update the internal list... |
| 52 | */ |
| 53 | static void page_remove_request(struct paging_bts *paging_bts) { |
| 54 | struct paging_request *to_be_deleted = paging_bts->last_request; |
| 55 | paging_bts->last_request = |
| 56 | (struct paging_request *)paging_bts->last_request->entry.next; |
| 57 | if (&to_be_deleted->entry == &paging_bts->pending_requests) |
| 58 | paging_bts->last_request = NULL; |
| 59 | llist_del(&to_be_deleted->entry); |
| 60 | free(to_be_deleted); |
| 61 | } |
| 62 | |
| 63 | |
| 64 | static void page_handle_pending_requests(void *data) { |
Harald Welte | 2f1311b | 2009-01-06 23:50:39 +0000 | [diff] [blame] | 65 | u_int8_t mi[128]; |
| 66 | unsigned long int tmsi; |
| 67 | unsigned int mi_len; |
Harald Welte | 38c2f13 | 2009-01-06 23:10:57 +0000 | [diff] [blame] | 68 | struct paging_bts *paging_bts = (struct paging_bts *)data; |
| 69 | |
| 70 | if (!paging_bts->last_request) |
| 71 | paging_bts->last_request = |
| 72 | (struct paging_request *)paging_bts->pending_requests.next; |
| 73 | if (&paging_bts->last_request->entry == &paging_bts->pending_requests) { |
| 74 | paging_bts->last_request = NULL; |
| 75 | return; |
| 76 | } |
| 77 | |
Harald Welte | 2f1311b | 2009-01-06 23:50:39 +0000 | [diff] [blame] | 78 | /* handle the paging request now */ |
Harald Welte | 38c2f13 | 2009-01-06 23:10:57 +0000 | [diff] [blame] | 79 | DEBUGP(DPAG, "Going to send paging commands: '%s'\n", |
| 80 | paging_bts->last_request->subscr->imsi); |
Harald Welte | 2f1311b | 2009-01-06 23:50:39 +0000 | [diff] [blame] | 81 | tmsi = strtoul(paging_bts->last_request->subscr->tmsi, NULL, 10); |
| 82 | mi_len = generate_mid_from_tmsi(mi, tmsi); |
| 83 | rsl_paging_cmd(paging_bts->bts, 1, mi_len, mi, RSL_CHANNEED_TCH_F); |
| 84 | |
| 85 | /* move to the next item */ |
| 86 | paging_bts->last_request = |
| 87 | (struct paging_request *)paging_bts->last_request->entry.next; |
| 88 | if (&paging_bts->last_request->entry == &paging_bts->pending_requests) |
| 89 | paging_bts->last_request = NULL; |
| 90 | |
Harald Welte | 38c2f13 | 2009-01-06 23:10:57 +0000 | [diff] [blame] | 91 | schedule_timer(&paging_bts->page_timer, PAGING_TIMEOUT); |
| 92 | } |
| 93 | |
Harald Welte | b68899d | 2009-01-06 21:47:18 +0000 | [diff] [blame] | 94 | static int page_pending_request(struct paging_bts *bts, |
| 95 | struct gsm_subscriber *subscr) { |
| 96 | struct paging_request *req; |
| 97 | |
| 98 | llist_for_each_entry(req, &bts->pending_requests, entry) { |
| 99 | if (subscr == req->subscr) |
| 100 | return 1; |
| 101 | } |
| 102 | |
| 103 | return 0; |
| 104 | } |
| 105 | |
| 106 | struct paging_bts* page_allocate(struct gsm_bts *bts) { |
| 107 | struct paging_bts *page; |
| 108 | |
| 109 | page = (struct paging_bts *)malloc(sizeof(*page)); |
| 110 | memset(page, 0, sizeof(*page)); |
Harald Welte | 38c2f13 | 2009-01-06 23:10:57 +0000 | [diff] [blame] | 111 | page->bts = bts; |
| 112 | INIT_LLIST_HEAD(&page->pending_requests); |
| 113 | page->page_timer.cb = page_handle_pending_requests; |
| 114 | page->page_timer.data = page; |
| 115 | |
Harald Welte | b68899d | 2009-01-06 21:47:18 +0000 | [diff] [blame] | 116 | llist_add_tail(&page->bts_list, &managed_bts); |
| 117 | |
| 118 | return page; |
| 119 | } |
| 120 | |
Harald Welte | 38c2f13 | 2009-01-06 23:10:57 +0000 | [diff] [blame] | 121 | void page_request(struct gsm_bts *bts, struct gsm_subscriber *subscr, int type) { |
Harald Welte | b68899d | 2009-01-06 21:47:18 +0000 | [diff] [blame] | 122 | struct paging_bts *bts_entry; |
| 123 | struct paging_request *req; |
| 124 | |
| 125 | req = (struct paging_request *)malloc(sizeof(*req)); |
| 126 | req->subscr = subscr_get(subscr); |
| 127 | req->bts = bts; |
Harald Welte | 38c2f13 | 2009-01-06 23:10:57 +0000 | [diff] [blame] | 128 | req->chan_type = type; |
Harald Welte | b68899d | 2009-01-06 21:47:18 +0000 | [diff] [blame] | 129 | |
| 130 | llist_for_each_entry(bts_entry, &managed_bts, bts_list) { |
| 131 | if (bts == bts_entry->bts && !page_pending_request(bts_entry, subscr)) { |
| 132 | llist_add_tail(&req->entry, &bts_entry->pending_requests); |
Harald Welte | 38c2f13 | 2009-01-06 23:10:57 +0000 | [diff] [blame] | 133 | if (!timer_pending(&bts_entry->page_timer)) |
| 134 | schedule_timer(&bts_entry->page_timer, PAGING_TIMEOUT); |
Harald Welte | b68899d | 2009-01-06 21:47:18 +0000 | [diff] [blame] | 135 | return; |
| 136 | } |
| 137 | } |
| 138 | |
Harald Welte | d08de2f | 2009-01-11 04:38:55 +0000 | [diff] [blame] | 139 | DEBUGP(DPAG, "Paging request for not managed BTS\n"); |
Harald Welte | b68899d | 2009-01-06 21:47:18 +0000 | [diff] [blame] | 140 | free(req); |
| 141 | return; |
| 142 | } |