[mobile] introduce and use gsm48_mmevevent_input()
... instead of using sequences of gsm48_mmevent_msgb_alloc() followed by gsm48_mmevent_msg()
This commit is contained in:
parent
584b917ced
commit
ea74fd6bc1
|
@ -210,8 +210,8 @@ struct gsm48_mm_conn {
|
|||
int gsm48_mm_init(struct osmocom_ms *ms);
|
||||
int gsm48_mm_exit(struct osmocom_ms *ms);
|
||||
struct msgb *gsm48_mmr_msgb_alloc(int msg_type);
|
||||
struct msgb *gsm48_mmevent_msgb_alloc(int msg_type);
|
||||
int gsm48_mmevent_msg(struct osmocom_ms *ms, struct msgb *msg);
|
||||
int gsm48_mmevent_input(struct osmocom_ms *ms, int msg_type,
|
||||
const uint8_t *data, unsigned int len);
|
||||
int gsm48_mmr_downmsg(struct osmocom_ms *ms, struct msgb *msg);
|
||||
int gsm48_rr_dequeue(struct osmocom_ms *ms);
|
||||
int gsm48_mmxx_dequeue(struct osmocom_ms *ms);
|
||||
|
|
|
@ -124,10 +124,7 @@ int mobile_exit(struct osmocom_ms *ms, int force)
|
|||
struct msgb *nmsg;
|
||||
|
||||
ms->shutdown = 1; /* going down */
|
||||
nmsg = gsm48_mmevent_msgb_alloc(GSM48_MM_EVENT_IMSI_DETACH);
|
||||
if (!nmsg)
|
||||
return -ENOMEM;
|
||||
gsm48_mmevent_msg(mm->ms, nmsg);
|
||||
gsm48_mmevent_input(ms, GSM48_MM_EVENT_IMSI_DETACH, NULL, 0);
|
||||
|
||||
return -EBUSY;
|
||||
}
|
||||
|
|
|
@ -1174,17 +1174,12 @@ static int gsm322_a_hplmn_search_start(struct osmocom_ms *ms, struct msgb *msg)
|
|||
/* manual mode selected */
|
||||
static int gsm322_a_sel_manual(struct osmocom_ms *ms, struct msgb *msg)
|
||||
{
|
||||
struct msgb *nmsg;
|
||||
|
||||
/* restart state machine */
|
||||
gsm322_a_switch_off(ms, msg);
|
||||
ms->settings.plmn_mode = PLMN_MODE_MANUAL;
|
||||
gsm322_m_switch_on(ms, msg);
|
||||
|
||||
nmsg = gsm48_mmevent_msgb_alloc(GSM48_MM_EVENT_USER_PLMN_SEL);
|
||||
if (!nmsg)
|
||||
return -ENOMEM;
|
||||
gsm48_mmevent_msg(ms, nmsg);
|
||||
gsm48_mmevent_input(ms, GSM48_MM_EVENT_USER_PLMN_SEL, NULL, 0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -1461,17 +1456,12 @@ static int gsm322_m_choose_plmn(struct osmocom_ms *ms, struct msgb *msg)
|
|||
/* auto mode selected */
|
||||
static int gsm322_m_sel_auto(struct osmocom_ms *ms, struct msgb *msg)
|
||||
{
|
||||
struct msgb *nmsg;
|
||||
|
||||
/* restart state machine */
|
||||
gsm322_m_switch_off(ms, msg);
|
||||
ms->settings.plmn_mode = PLMN_MODE_AUTO;
|
||||
gsm322_a_switch_on(ms, msg);
|
||||
|
||||
nmsg = gsm48_mmevent_msgb_alloc(GSM48_MM_EVENT_USER_PLMN_SEL);
|
||||
if (!nmsg)
|
||||
return -ENOMEM;
|
||||
gsm48_mmevent_msg(ms, nmsg);
|
||||
gsm48_mmevent_input(ms, GSM48_MM_EVENT_USER_PLMN_SEL, NULL, 0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -2684,14 +2674,8 @@ static int gsm322_c_any_cell_sel(struct osmocom_ms *ms, struct msgb *msg)
|
|||
/* after re-selection, indicate no cell found */
|
||||
if (cs->state == GSM322_C6_ANY_CELL_SEL
|
||||
|| cs->state == GSM322_C8_ANY_CELL_RESEL) {
|
||||
struct msgb *nmsg;
|
||||
|
||||
/* tell that we have no cell found */
|
||||
nmsg = gsm48_mmevent_msgb_alloc(GSM48_MM_EVENT_NO_CELL_FOUND);
|
||||
if (!nmsg)
|
||||
return -ENOMEM;
|
||||
gsm48_mmevent_msg(ms, nmsg);
|
||||
|
||||
gsm48_mmevent_input(ms, GSM48_MM_EVENT_NO_CELL_FOUND, NULL, 0);
|
||||
} else {
|
||||
new_c_state(cs, GSM322_C6_ANY_CELL_SEL);
|
||||
}
|
||||
|
@ -2737,7 +2721,6 @@ static int gsm322_c_any_cell_resel(struct osmocom_ms *ms, struct msgb *msg)
|
|||
static int gsm322_c_camp_normally(struct osmocom_ms *ms, struct msgb *msg)
|
||||
{
|
||||
struct gsm322_cellsel *cs = &ms->cellsel;
|
||||
struct msgb *nmsg;
|
||||
|
||||
LOGP(DSUM, LOGL_INFO, "Camping normally on cell (arfcn=%d mcc=%s "
|
||||
"mnc=%s %s, %s)\n", cs->sel_arfcn, gsm_print_mcc(cs->sel_mcc),
|
||||
|
@ -2745,10 +2728,7 @@ static int gsm322_c_camp_normally(struct osmocom_ms *ms, struct msgb *msg)
|
|||
gsm_get_mnc(cs->sel_mcc, cs->sel_mnc));
|
||||
|
||||
/* tell that we have selected a (new) cell */
|
||||
nmsg = gsm48_mmevent_msgb_alloc(GSM48_MM_EVENT_CELL_SELECTED);
|
||||
if (!nmsg)
|
||||
return -ENOMEM;
|
||||
gsm48_mmevent_msg(ms, nmsg);
|
||||
gsm48_mmevent_input(ms, GSM48_MM_EVENT_CELL_SELECTED, NULL, 0);
|
||||
|
||||
new_c_state(cs, GSM322_C3_CAMPED_NORMALLY);
|
||||
|
||||
|
@ -2759,7 +2739,6 @@ static int gsm322_c_camp_normally(struct osmocom_ms *ms, struct msgb *msg)
|
|||
static int gsm322_c_camp_any_cell(struct osmocom_ms *ms, struct msgb *msg)
|
||||
{
|
||||
struct gsm322_cellsel *cs = &ms->cellsel;
|
||||
struct msgb *nmsg;
|
||||
|
||||
LOGP(DSUM, LOGL_INFO, "Camping on any cell (arfcn=%d mcc=%s "
|
||||
"mnc=%s %s, %s)\n", cs->sel_arfcn, gsm_print_mcc(cs->sel_mcc),
|
||||
|
@ -2768,10 +2747,7 @@ static int gsm322_c_camp_any_cell(struct osmocom_ms *ms, struct msgb *msg)
|
|||
|
||||
|
||||
/* tell that we have selected a (new) cell */
|
||||
nmsg = gsm48_mmevent_msgb_alloc(GSM48_MM_EVENT_CELL_SELECTED);
|
||||
if (!nmsg)
|
||||
return -ENOMEM;
|
||||
gsm48_mmevent_msg(ms, nmsg);
|
||||
gsm48_mmevent_input(ms, GSM48_MM_EVENT_CELL_SELECTED, NULL, 0);
|
||||
|
||||
new_c_state(cs, GSM322_C7_CAMPED_ANY_CELL);
|
||||
|
||||
|
@ -2878,8 +2854,6 @@ static int gsm322_c_choose_cell(struct osmocom_ms *ms, struct msgb *msg)
|
|||
|
||||
/* After location updating, we choose the last cell */
|
||||
if (gm->same_cell) {
|
||||
struct msgb *nmsg;
|
||||
|
||||
if (!cs->selected) {
|
||||
printf("No cell selected when ret.idle, please fix!\n");
|
||||
exit(0L);
|
||||
|
@ -2896,10 +2870,7 @@ static int gsm322_c_choose_cell(struct osmocom_ms *ms, struct msgb *msg)
|
|||
new_c_state(cs, GSM322_C3_CAMPED_NORMALLY);
|
||||
|
||||
/* tell that we have selected the cell, so RR returns IDLE */
|
||||
nmsg = gsm48_mmevent_msgb_alloc(GSM48_MM_EVENT_CELL_SELECTED);
|
||||
if (!nmsg)
|
||||
return -ENOMEM;
|
||||
gsm48_mmevent_msg(ms, nmsg);
|
||||
gsm48_mmevent_input(ms, GSM48_MM_EVENT_CELL_SELECTED, NULL, 0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -658,7 +658,7 @@ struct msgb *gsm48_mmxx_msgb_alloc(int msg_type, uint32_t ref,
|
|||
}
|
||||
|
||||
/* allocate MM event message */
|
||||
struct msgb *gsm48_mmevent_msgb_alloc(int msg_type)
|
||||
static struct msgb *gsm48_mmevent_msgb_alloc(int msg_type)
|
||||
{
|
||||
struct msgb *msg;
|
||||
struct gsm48_mm_event *mme;
|
||||
|
@ -710,7 +710,7 @@ int gsm48_mmr_downmsg(struct osmocom_ms *ms, struct msgb *msg)
|
|||
}
|
||||
|
||||
/* queue MM event message */
|
||||
int gsm48_mmevent_msg(struct osmocom_ms *ms, struct msgb *msg)
|
||||
static int gsm48_mmevent_msg(struct osmocom_ms *ms, struct msgb *msg)
|
||||
{
|
||||
struct gsm48_mmlayer *mm = &ms->mmlayer;
|
||||
|
||||
|
@ -905,14 +905,10 @@ static void new_mm_state(struct gsm48_mmlayer *mm, int state, int substate)
|
|||
|
||||
/* resend detach event, if flag is set */
|
||||
if (state == GSM48_MM_ST_MM_IDLE && mm->delay_detach) {
|
||||
struct msgb *nmsg;
|
||||
|
||||
mm->delay_detach = 0;
|
||||
|
||||
nmsg = gsm48_mmevent_msgb_alloc(GSM48_MM_EVENT_IMSI_DETACH);
|
||||
if (!nmsg)
|
||||
return;
|
||||
gsm48_mmevent_msg(mm->ms, nmsg);
|
||||
gsm48_mmevent_input(mm->ms, GSM48_MM_EVENT_IMSI_DETACH,
|
||||
NULL, 0);
|
||||
}
|
||||
|
||||
/* 4.4.2 start T3212 in MM IDLE mode if not started or has expired */
|
||||
|
@ -2431,7 +2427,8 @@ static int gsm48_mm_rel_loc_upd_rej(struct osmocom_ms *ms, struct msgb *msg)
|
|||
}
|
||||
memset(&ngm, 0, sizeof(ngm));
|
||||
ngm.reject = mm->lupd_rej_cause;
|
||||
gsm322_event_input(ms, GSM322_EVT_PLMN, msg_type, &ngm, sizeof(ngm));
|
||||
gsm322_event_input(ms, GSM322_EVT_PLMN, msg_type,
|
||||
(uint8_t *)&ngm, sizeof(ngm));
|
||||
|
||||
/* forbidden list */
|
||||
switch (mm->lupd_rej_cause) {
|
||||
|
@ -4088,13 +4085,7 @@ static int gsm48_mmr_reg_req(struct osmocom_ms *ms)
|
|||
/* trigger detach of sim card */
|
||||
static int gsm48_mmr_nreg_req(struct osmocom_ms *ms)
|
||||
{
|
||||
struct gsm48_mmlayer *mm = &ms->mmlayer;
|
||||
struct msgb *nmsg;
|
||||
|
||||
nmsg = gsm48_mmevent_msgb_alloc(GSM48_MM_EVENT_IMSI_DETACH);
|
||||
if (!nmsg)
|
||||
return -ENOMEM;
|
||||
gsm48_mmevent_msg(mm->ms, nmsg);
|
||||
gsm48_mmevent_input(ms, GSM48_MM_EVENT_IMSI_DETACH, NULL, 0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -4121,4 +4112,22 @@ static int gsm48_rcv_mmr(struct osmocom_ms *ms, struct msgb *msg)
|
|||
return rc;
|
||||
}
|
||||
|
||||
int gsm48_mmevent_input(struct osmocom_ms *ms, int msg_type,
|
||||
const uint8_t *data, unsigned int len)
|
||||
{
|
||||
struct msgb *nmsg = gsm48_mmevent_msgb_alloc(msg_type);
|
||||
int rc;
|
||||
|
||||
if (!nmsg)
|
||||
return -ENOMEM;
|
||||
|
||||
if (data && len) {
|
||||
uint8_t *cur = msgb_push(nmsg, len);
|
||||
if (!cur) {
|
||||
msgb_free(nmsg);
|
||||
return -EIO;
|
||||
}
|
||||
memcpy(cur, data, len);
|
||||
}
|
||||
return gsm48_mmevent_msg(ms, nmsg);
|
||||
}
|
||||
|
|
|
@ -1560,7 +1560,6 @@ fail:
|
|||
static int gsm48_new_sysinfo(struct osmocom_ms *ms, uint8_t type)
|
||||
{
|
||||
struct gsm48_sysinfo *s = ms->cellsel.si;
|
||||
struct msgb *nmsg;
|
||||
struct gsm322_msg em;
|
||||
|
||||
/* update list of measurements, if BA(SACCH) is complete and new */
|
||||
|
@ -1600,10 +1599,7 @@ static int gsm48_new_sysinfo(struct osmocom_ms *ms, uint8_t type)
|
|||
(uint8_t *)&em, sizeof(em));
|
||||
|
||||
/* send timer info to location update process */
|
||||
nmsg = gsm48_mmevent_msgb_alloc(GSM48_MM_EVENT_SYSINFO);
|
||||
if (!nmsg)
|
||||
return -ENOMEM;
|
||||
gsm48_mmevent_msg(ms, nmsg);
|
||||
gsm48_mmevent_input(ms, GSM48_MM_EVENT_SYSINFO, NULL, 0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -855,25 +855,16 @@ int gsm_subscr_generate_kc(struct osmocom_ms *ms, uint8_t key_seq,
|
|||
if ((subscr->sim_type != GSM_SIM_TYPE_READER
|
||||
&& subscr->sim_type != GSM_SIM_TYPE_TEST)
|
||||
|| !subscr->sim_valid || no_sim) {
|
||||
struct gsm48_mm_event *nmme;
|
||||
uint8_t dummy_sres[4] = { 0x12, 0x34, 0x56, 0x78 };
|
||||
|
||||
LOGP(DMM, LOGL_INFO, "Sending dummy authentication response\n");
|
||||
nmsg = gsm48_mmevent_msgb_alloc(GSM48_MM_EVENT_AUTH_RESPONSE);
|
||||
if (!nmsg)
|
||||
return -ENOMEM;
|
||||
nmme = (struct gsm48_mm_event *) nmsg->data;
|
||||
nmme->sres[0] = 0x12;
|
||||
nmme->sres[1] = 0x34;
|
||||
nmme->sres[2] = 0x56;
|
||||
nmme->sres[3] = 0x78;
|
||||
gsm48_mmevent_msg(ms, nmsg);
|
||||
|
||||
gsm48_mmevent_input(ms, GSM48_MM_EVENT_AUTH_RESPONSE,
|
||||
dummy_sres, sizeof(dummy_sres));
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* test SIM */
|
||||
if (subscr->sim_type == GSM_SIM_TYPE_TEST) {
|
||||
struct gsm48_mm_event *nmme;
|
||||
uint8_t sres[4];
|
||||
struct gsm_settings *set = &ms->settings;
|
||||
|
||||
|
@ -885,12 +876,8 @@ int gsm_subscr_generate_kc(struct osmocom_ms *ms, uint8_t key_seq,
|
|||
subscr->key_seq = key_seq;
|
||||
|
||||
LOGP(DMM, LOGL_INFO, "Sending authentication response\n");
|
||||
nmsg = gsm48_mmevent_msgb_alloc(GSM48_MM_EVENT_AUTH_RESPONSE);
|
||||
if (!nmsg)
|
||||
return -ENOMEM;
|
||||
nmme = (struct gsm48_mm_event *) nmsg->data;
|
||||
memcpy(nmme->sres, sres, 4);
|
||||
gsm48_mmevent_msg(ms, nmsg);
|
||||
gsm48_mmevent_input(ms, GSM48_MM_EVENT_AUTH_RESPONSE,
|
||||
sres, sizeof(sres));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -924,7 +911,6 @@ static void subscr_sim_key_cb(struct osmocom_ms *ms, struct msgb *msg)
|
|||
uint16_t payload_len = msg->len - sizeof(*sh);
|
||||
struct msgb *nmsg;
|
||||
struct sim_hdr *nsh;
|
||||
struct gsm48_mm_event *nmme;
|
||||
uint8_t *data;
|
||||
|
||||
/* error handling */
|
||||
|
@ -961,12 +947,7 @@ static void subscr_sim_key_cb(struct osmocom_ms *ms, struct msgb *msg)
|
|||
sim_job(ms, nmsg);
|
||||
|
||||
/* return signed response */
|
||||
nmsg = gsm48_mmevent_msgb_alloc(GSM48_MM_EVENT_AUTH_RESPONSE);
|
||||
if (!nmsg)
|
||||
return;
|
||||
nmme = (struct gsm48_mm_event *) nmsg->data;
|
||||
memcpy(nmme->sres, payload, 4);
|
||||
gsm48_mmevent_msg(ms, nmsg);
|
||||
gsm48_mmevent_input(ms, GSM48_MM_EVENT_AUTH_RESPONSE, payload, 4);
|
||||
|
||||
msgb_free(msg);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue