+/* decode "Mobile Allocation" (10.5.2.21) */
+static int gsm48_decode_mobile_alloc(struct gsm48_sysinfo *s, uint8_t *ma, uint8_t len)
+{
+ int i, j = 0;
+ uint16_t f[len << 3];
+
+ /* tabula rasa */
+ s->hopp_len = 0;
+
+ /* generating list of all frequencies (1..1023,0) */
+ for (i = 1; i <= 1024; i++) {
+ if ((s->freq[i & 1023] & FREQ_TYPE_SERV)) {
+ f[j++] = i & 1023;
+ if (j == (len << 3))
+ break;
+ }
+ }
+
+ /* fill hopping table with frequency index given by IE */
+ for (i = 0, i < (len << 3), i++) {
+ /* if bit is set, this frequency index is used for hopping */
+ if ((ma[len - 1 - (i >> 3)] & (1 << (i & 7)))) {
+ /* index higher than entries in list ? */
+ if (i >= j) {
+ DEBUGP(DRR, "Mobile Allocation hopping index "
+ "%d exceeds maximum number of cell "
+ "frequencies. (%d)\n", i + 1, j);
+ break;
+ }
+ hopping[s->hopp_len++] = f[i];
+ }
+ }
+
+ return 0;
+}
+