aboutsummaryrefslogtreecommitdiffstats
path: root/src/gprs_ms.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/gprs_ms.h')
-rw-r--r--src/gprs_ms.h101
1 files changed, 59 insertions, 42 deletions
diff --git a/src/gprs_ms.h b/src/gprs_ms.h
index 6674261a..276733ca 100644
--- a/src/gprs_ms.h
+++ b/src/gprs_ms.h
@@ -12,10 +12,6 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#pragma once
@@ -35,6 +31,7 @@ extern "C" {
#include <osmocom/core/timer.h>
#include <osmocom/core/linuxlist.h>
#include <osmocom/core/rate_ctr.h>
+#include <osmocom/core/use_count.h>
#include <osmocom/gsm/protocol/gsm_23_003.h>
#include <osmocom/gsm/gsm48.h>
@@ -54,20 +51,16 @@ struct gprs_rlcmac_bts;
struct gprs_rlcmac_trx;
struct GprsMs;
-struct gpr_ms_callback {
- void (*ms_idle)(struct GprsMs *);
- void (*ms_active)(struct GprsMs *);
-};
-
struct GprsMs {
struct llist_head list; /* list of all GprsMs */
- struct gpr_ms_callback cb;
bool app_info_pending;
struct gprs_rlcmac_bts *bts;
struct gprs_rlcmac_ul_tbf *ul_tbf;
struct gprs_rlcmac_dl_tbf *dl_tbf;
struct llist_head old_tbfs; /* list of gprs_rlcmac_tbf */
+ /* First common timeslot used both in UL and DL, or NULL if not set: */
+ struct gprs_rlcmac_pdch *first_common_ts;
uint32_t tlli;
uint32_t new_ul_tlli;
@@ -83,11 +76,12 @@ struct GprsMs {
enum CodingScheme current_cs_dl;
struct gprs_llc_queue llc_queue;
+ struct osmo_timer_list llc_timer;
- bool is_idle;
- int ref;
- struct osmo_timer_list timer;
- unsigned delay;
+ struct osmo_use_count use_count;
+ struct osmo_timer_list release_timer;
+ /* Time at which MS became idle and waiting to be released by release_timer: */
+ struct timeval tv_idle_start;
int64_t last_cs_not_low;
@@ -96,21 +90,18 @@ struct GprsMs {
uint8_t reserved_dl_slots;
uint8_t reserved_ul_slots;
struct gprs_rlcmac_trx *current_trx;
-
- struct gprs_codel *codel_state;
enum mcs_kind mode;
struct rate_ctr_group *ctrs;
struct nacc_fsm_ctx *nacc;
};
-struct GprsMs *ms_alloc(struct gprs_rlcmac_bts *bts, uint32_t tlli);
+struct GprsMs *ms_alloc(struct gprs_rlcmac_bts *bts, const char *use_ref);
-int ms_first_common_ts(const struct GprsMs *ms);
+struct gprs_rlcmac_pdch *ms_first_common_ts(const struct GprsMs *ms);
+void ms_set_first_common_ts(struct GprsMs *ms, struct gprs_rlcmac_pdch *pdch);
void ms_set_reserved_slots(struct GprsMs *ms, struct gprs_rlcmac_trx *trx,
uint8_t ul_slots, uint8_t dl_slots);
-struct GprsMs *ms_ref(struct GprsMs *ms);
-void ms_unref(struct GprsMs *ms);
void ms_set_mode(struct GprsMs *ms, enum mcs_kind mode);
void ms_set_ms_class(struct GprsMs *ms, uint8_t ms_class_);
void ms_set_egprs_ms_class(struct GprsMs *ms, uint8_t ms_class_);
@@ -124,6 +115,7 @@ void ms_set_current_cs_dl(struct GprsMs *ms, enum CodingScheme scheme);
void ms_update_error_rate(struct GprsMs *ms, struct gprs_rlcmac_tbf *tbf, int error_rate);
uint8_t ms_current_pacch_slots(const struct GprsMs *ms);
+void ms_update_announced_tlli(struct GprsMs *ms, uint32_t tlli);
void ms_merge_and_clear_ms(struct GprsMs *ms, struct GprsMs *old_ms);
void ms_attach_tbf(struct GprsMs *ms, struct gprs_rlcmac_tbf *tbf);
@@ -139,16 +131,25 @@ struct gprs_rlcmac_tbf *ms_tbf(const struct GprsMs *ms, enum gprs_rlcmac_tbf_dir
static inline struct gprs_rlcmac_ul_tbf *ms_ul_tbf(const struct GprsMs *ms) {return ms->ul_tbf;}
static inline struct gprs_rlcmac_dl_tbf *ms_dl_tbf(const struct GprsMs *ms) {return ms->dl_tbf;}
-
-void ms_set_callback(struct GprsMs *ms, struct gpr_ms_callback *cb);
+const char *ms_name(const struct GprsMs *ms);
+char *ms_name_buf(const struct GprsMs *ms, char *buf, unsigned int buf_size);
int ms_nacc_start(struct GprsMs *ms, Packet_Cell_Change_Notification_t *notif);
bool ms_nacc_rts(const struct GprsMs *ms);
-struct msgb *ms_nacc_create_rlcmac_msg(struct GprsMs *ms, struct gprs_rlcmac_tbf *tbf, uint32_t fn, uint8_t ts);
+struct msgb *ms_nacc_create_rlcmac_msg(struct GprsMs *ms, struct gprs_rlcmac_tbf *tbf,
+ const struct gprs_rlcmac_pdch *pdch, uint32_t fn);
+
+struct gprs_rlcmac_ul_tbf *ms_new_ul_tbf_assigned_pacch(struct GprsMs *ms, int8_t use_trx);
+struct gprs_rlcmac_ul_tbf *ms_new_ul_tbf_assigned_agch(struct GprsMs *ms);
+struct gprs_rlcmac_ul_tbf *ms_new_ul_tbf_rejected_pacch(struct GprsMs *ms, struct gprs_rlcmac_pdch *pdch);
+int ms_new_dl_tbf_assigned_on_pacch(struct GprsMs *ms, struct gprs_rlcmac_tbf *tbf);
+int ms_new_dl_tbf_assigned_on_pch(struct GprsMs *ms);
+int ms_append_llc_dl_data(struct GprsMs *ms, uint16_t pdu_delay_csec, const uint8_t *data, uint16_t len);
static inline bool ms_is_idle(const struct GprsMs *ms)
{
- return !ms->ul_tbf && !ms->dl_tbf && !ms->ref && llist_empty(&ms->old_tbfs);
+ return !ms->ul_tbf && !ms->dl_tbf &&
+ llist_empty(&ms->old_tbfs);
}
static inline struct gprs_llc_queue *ms_llc_queue(struct GprsMs *ms)
@@ -156,11 +157,30 @@ static inline struct gprs_llc_queue *ms_llc_queue(struct GprsMs *ms)
return &ms->llc_queue;
}
+/* Function used in code where a ul_tbf related event occurs and hence its state
+ * changes, which in turn may change the entire MS state (eg becoming reachable
+ * over PCH or PACCH) and the caller may want to know if it is a good time to
+ * assign a DL TBF (and whether we have DL data to send) */
static inline bool ms_need_dl_tbf(struct GprsMs *ms)
{
- if (ms_dl_tbf(ms) != NULL &&
- tbf_state((const struct gprs_rlcmac_tbf *)ms_dl_tbf(ms)) != GPRS_RLCMAC_WAIT_RELEASE)
- return false;
+ struct gprs_rlcmac_dl_tbf *dl_tbf = ms_dl_tbf(ms);
+ if (dl_tbf) {
+ switch (tbf_state(dl_tbf_as_tbf(dl_tbf))) {
+ case TBF_ST_NEW:
+ case TBF_ST_ASSIGN:
+ case TBF_ST_FLOW:
+ case TBF_ST_FINISHED:
+ case TBF_ST_WAIT_RELEASE:
+ return false; /* TBF in use, hence no need for new DL TBF */
+ case TBF_ST_WAIT_REUSE_TFI:
+ case TBF_ST_RELEASING:
+ /* TBF cannot be used to send further data, a new one
+ * may be needed, check below */
+ break;
+ default:
+ OSMO_ASSERT(0);
+ }
+ }
return llc_queue_size(ms_llc_queue(ms)) > 0;
}
@@ -186,6 +206,11 @@ static inline const char *ms_imsi(const struct GprsMs *ms)
return ms->imsi;
}
+static inline bool ms_imsi_is_valid(const struct GprsMs *ms)
+{
+ return ms->imsi[0] != '\0';
+}
+
static inline uint8_t ms_ta(const struct GprsMs *ms)
{
return ms->ta;
@@ -211,16 +236,6 @@ static inline enum mcs_kind ms_mode(const struct GprsMs *ms)
return ms->mode;
}
-static inline void ms_set_timeout(struct GprsMs *ms, unsigned secs)
-{
- ms->delay = secs;
-}
-
-static inline struct gprs_codel *ms_codel_state(const struct GprsMs *ms)
-{
- return ms->codel_state;
-}
-
static inline unsigned ms_nack_rate_dl(const struct GprsMs *ms)
{
return ms->nack_rate_dl;
@@ -241,12 +256,14 @@ static inline struct gprs_rlcmac_trx *ms_current_trx(const struct GprsMs *ms)
return ms->current_trx;
}
+#define MS_USE_TBF "tbf"
+#define ms_ref(ms, use) \
+ OSMO_ASSERT(osmo_use_count_get_put(&(ms)->use_count, use, 1) == 0)
+#define ms_unref(ms, use) \
+ OSMO_ASSERT(osmo_use_count_get_put(&(ms)->use_count, use, -1) == 0)
+
#define LOGPMS(ms, category, level, fmt, args...) \
- LOGP(category, level, "MS(TLLI=0x%08x, IMSI=%s, TA=%" PRIu8 ", %" PRIu8 "/%" PRIu8 ",%s%s) " fmt, \
- ms_tlli(ms), ms_imsi(ms), ms_ta(ms), ms_ms_class(ms), ms_egprs_ms_class(ms), \
- ms_ul_tbf(ms) ? " UL": "", \
- ms_dl_tbf(ms) ? " DL": "", \
- ## args)
+ LOGP(category, level, "%s " fmt, ms_name(ms), ## args)
#ifdef __cplusplus
}