cdr: Remember the charging id supplied by the GGSN

The charging_id is provided by the GGSN. Copy it into the CDR
part of the data structure so it will remain present until after
the pdp context has been deleted.
diff --git a/openbsc/include/openbsc/gprs_sgsn.h b/openbsc/include/openbsc/gprs_sgsn.h
index c88a2bb..4bbde9c 100644
--- a/openbsc/include/openbsc/gprs_sgsn.h
+++ b/openbsc/include/openbsc/gprs_sgsn.h
@@ -212,6 +212,7 @@
 	struct timespec		cdr_start;	/* The start of the CDR */
 	uint64_t		cdr_bytes_in;
 	uint64_t		cdr_bytes_out;
+	uint32_t		cdr_charging_id;
 };
 
 #define LOGPDPCTXP(level, pdp, fmt, args...) \
diff --git a/openbsc/src/gprs/sgsn_cdr.c b/openbsc/src/gprs/sgsn_cdr.c
index 0fcdd3b..04084f5 100644
--- a/openbsc/src/gprs/sgsn_cdr.c
+++ b/openbsc/src/gprs/sgsn_cdr.c
@@ -64,7 +64,7 @@
 	if (ftell(cdr_file) != 0)
 		return;
 
-	fprintf(cdr_file, "timestamp,imsi,imei,msisdn,cell_id,lac,event,pdp_duration,ggsn_addr,sgsn_addr,apni,eua_addr,vol_in,vol_out\n");
+	fprintf(cdr_file, "timestamp,imsi,imei,msisdn,cell_id,lac,event,pdp_duration,ggsn_addr,sgsn_addr,apni,eua_addr,vol_in,vol_out,charging_id\n");
 }
 
 static void cdr_log_mm(struct sgsn_instance *inst, const char *ev,
@@ -171,7 +171,7 @@
 	duration = tp.tv_sec - pdp->cdr_start.tv_sec;
 
 	fprintf(cdr_file,
-		"%04d%02d%02d%02d%02d%02d%03d,%s,%s,%s,%d,%d,%s,%ld,%s,%s,%s,%s,%" PRIu64 ",%" PRIu64 "\n",
+		"%04d%02d%02d%02d%02d%02d%03d,%s,%s,%s,%d,%d,%s,%ld,%s,%s,%s,%s,%" PRIu64 ",%" PRIu64 ",%u\n",
 		tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
 		tm.tm_hour, tm.tm_min, tm.tm_sec,
 		(int)(tv.tv_usec / 1000),
@@ -187,7 +187,8 @@
 		apni,
 		eua_addr,
 		pdp->cdr_bytes_in,
-		pdp->cdr_bytes_out);
+		pdp->cdr_bytes_out,
+		pdp->cdr_charging_id);
 	fclose(cdr_file);
 }
 
@@ -222,6 +223,7 @@
 		break;
 	case S_SGSN_PDP_ACT:
 		clock_gettime(CLOCK_MONOTONIC, &signal_data->pdp->cdr_start);
+		signal_data->pdp->cdr_charging_id = signal_data->pdp->lib->cid;
 		cdr_log_pdp(inst, "pdp-act", signal_data->pdp);
 		signal_data->pdp->cdr_timer.cb = cdr_pdp_timeout;
 		signal_data->pdp->cdr_timer.data = signal_data->pdp;