Harald Welte | 0e3e88e | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 1 | |
| 2 | #include <openbsc/linuxlist.h> |
| 3 | |
| 4 | struct network_info { |
| 5 | struct llist_head list; |
| 6 | |
| 7 | u_int16_t mcc; |
| 8 | u_int16_t mnc; |
| 9 | |
| 10 | struct llist_head bcch_infos; |
| 11 | }; |
| 12 | |
| 13 | static LLIST_HEAD(bcch_infos); |
| 14 | |
| 15 | static LLIST_HEAD(network_infos); |
| 16 | |
| 17 | static struct network_info *network_find(u_int16_t mcc, u_int16_t mnc) |
| 18 | { |
| 19 | struct network_info *ni; |
| 20 | |
| 21 | llist_for_each_head(ni, &network_infos, list) { |
| 22 | if (ni->mcc == mcc && ni->mnc == mnc) |
| 23 | return ni; |
| 24 | } |
| 25 | |
| 26 | return NULL; |
| 27 | } |
| 28 | |
| 29 | static struct network_info *network_alloc(u_int16_t mcc, u_int16_t mnc) |
| 30 | { |
| 31 | struct network_info *ni = talloc_zero(NULL, struct network_info); |
| 32 | |
| 33 | if (!ni) |
| 34 | return NULL; |
| 35 | |
| 36 | ni->mcc = mcc; |
| 37 | ni->mnc = mnc; |
| 38 | |
| 39 | llist_add_tail(&ni->list, &network_infos); |
| 40 | |
| 41 | return ni; |
| 42 | } |
| 43 | |
| 44 | /* here we get handed in the BCCH info structure */ |
| 45 | int receive_bcch_info(const struct ipac_bcch_info *binfo) |
| 46 | { |
| 47 | struct ipac_bcch_info *binfo2; |
| 48 | struct network_info *ni; |
| 49 | |
| 50 | binfo2 = talloc_zero(NULL, struct ipac_bcch_info); |
| 51 | if (!binfo2) |
| 52 | return -ENOMEM; |
| 53 | |
| 54 | memcpy(binfo2, binfo, sizeof(*binfo2)); |
| 55 | |
| 56 | ni = network_find(binfo->cgi.mcc, binfo->cgi.mnc); |
| 57 | if (!ni) |
| 58 | ni = network_alloc(binfo->cgi.mcc, binfo->cgi.mnc); |
| 59 | |
| 60 | llist_add_tail(&binfo2->list, &ni->bcch_infos); |
| 61 | |
| 62 | return 0; |
| 63 | } |
| 64 | |
| 65 | |