patch the SI and NM attr tables independently
diff --git a/openbsc/src/bsc_hack.c b/openbsc/src/bsc_hack.c
index 1e33c5d..ecda62d 100644
--- a/openbsc/src/bsc_hack.c
+++ b/openbsc/src/bsc_hack.c
@@ -63,6 +63,8 @@
 static const char *config_file = "openbsc.cfg";
 extern int ipacc_rtp_direct;
 
+static void patch_nm_tables(struct gsm_bts *bts);
+static void patch_si_tables(struct gsm_bts *bts);
 
 /* The following definitions are for OM and NM packets that we cannot yet
  * generate by code but we just pass on */
@@ -390,6 +392,7 @@
 		case NM_OC_BTS:
 			bts = obj;
 			if (new_state->availability == 5) {
+				patch_nm_tables(bts);
 				abis_nm_set_bts_attr(bts, nanobts_attr_bts,
 							sizeof(nanobts_attr_bts));
 				abis_nm_opstart(bts, NM_OC_BTS,
@@ -444,6 +447,7 @@
 					NM_STATE_UNLOCKED);
 		break;
 	case NM_OC_RADIO_CARRIER:
+		patch_nm_tables(trx->bts);
 		abis_nm_set_radio_attr(trx, nanobts_attr_radio,
 					sizeof(nanobts_attr_radio));
 		abis_nm_opstart(trx->bts, NM_OC_RADIO_CARRIER,
@@ -514,6 +518,8 @@
 	struct gsm_e1_subslot *e1l = &trx->rsl_e1_link;
 	int i;
 
+	patch_nm_tables(trx->bts);
+
 	switch (trx->bts->type) {
 	case GSM_BTS_TYPE_BS11:
 		/* FIXME: discover this by fetching an attribute */
@@ -876,10 +882,41 @@
  * Patch the various SYSTEM INFORMATION tables to update
  * the LAI
  */
-static void patch_tables(struct gsm_bts *bts)
+static void patch_nm_tables(struct gsm_bts *bts)
 {
 	u_int8_t arfcn_low = bts->c0->arfcn & 0xff;
 	u_int8_t arfcn_high = (bts->c0->arfcn >> 8) & 0x0f;
+
+	/* patch ARFCN into BTS Attributes */
+	bs11_attr_bts[69] &= 0xf0;
+	bs11_attr_bts[69] |= arfcn_high;
+	bs11_attr_bts[70] = arfcn_low;
+	nanobts_attr_bts[42] &= 0xf0;
+	nanobts_attr_bts[42] |= arfcn_high;
+	nanobts_attr_bts[43] = arfcn_low;
+
+	/* patch ARFCN into TRX Attributes */
+	bs11_attr_radio[2] &= 0xf0;
+	bs11_attr_radio[2] |= arfcn_high;
+	bs11_attr_radio[3] = arfcn_low;
+	nanobts_attr_radio[5] &= 0xf0;
+	nanobts_attr_radio[5] |= arfcn_high;
+	nanobts_attr_radio[6] = arfcn_low;
+
+	/* patch BSIC */
+	bs11_attr_bts[1] = bts->bsic;
+	nanobts_attr_bts[sizeof(nanobts_attr_bts)-1] = bts->bsic;
+}
+
+/*
+ * Patch the various SYSTEM INFORMATION tables to update
+ * the LAI
+ */
+static void patch_si_tables(struct gsm_bts *bts)
+{
+	u_int8_t arfcn_low = bts->c0->arfcn & 0xff;
+	u_int8_t arfcn_high = (bts->c0->arfcn >> 8) & 0x0f;
+
 	/* covert the raw packet to the struct */
 	struct gsm48_system_information_type_1 *type_1 =
 		(struct gsm48_system_information_type_1*)&si1;
@@ -902,22 +939,6 @@
 	type_4->lai = lai;
 	type_6->lai = lai;
 
-	/* patch ARFCN into BTS Attributes */
-	bs11_attr_bts[69] &= 0xf0;
-	bs11_attr_bts[69] |= arfcn_high;
-	bs11_attr_bts[70] = arfcn_low;
-	nanobts_attr_bts[42] &= 0xf0;
-	nanobts_attr_bts[42] |= arfcn_high;
-	nanobts_attr_bts[43] = arfcn_low;
-
-	/* patch ARFCN into TRX Attributes */
-	bs11_attr_radio[2] &= 0xf0;
-	bs11_attr_radio[2] |= arfcn_high;
-	bs11_attr_radio[3] = arfcn_low;
-	nanobts_attr_radio[5] &= 0xf0;
-	nanobts_attr_radio[5] |= arfcn_high;
-	nanobts_attr_radio[6] = arfcn_low;
-
 	type_4->data[2] &= 0xf0;
 	type_4->data[2] |= arfcn_high;
 	type_4->data[3] = arfcn_low;
@@ -925,10 +946,6 @@
 	/* patch Control Channel Description 10.5.2.11 */
 	type_3->control_channel_desc = bts->chan_desc;
 
-	/* patch BSIC */
-	bs11_attr_bts[1] = bts->bsic;
-	nanobts_attr_bts[sizeof(nanobts_attr_bts)-1] = bts->bsic;
-
 	/* patch TSC */
 	si4[15] &= ~0xe0;
 	si4[15] |= (bts->tsc & 7) << 5;
@@ -957,6 +974,7 @@
 		"using MCC=%u MNC=%u BSIC=%u TSC=%u\n",
 		trx->bts->nr, trx->nr, gsmnet->country_code, 
 		gsmnet->network_code, trx->bts->bsic, trx->bts->tsc);
+	patch_si_tables(trx->bts);
 	set_system_infos(trx);
 }
 
@@ -1013,8 +1031,6 @@
 	bts->chan_desc.bs_pa_mfrms = RSL_BS_PA_MFRMS_5;
 	bts->chan_desc.t3212 = 0;
 
-	patch_tables(bts);
-
 	paging_init(bts);
 
 	return 0;