blob: ec6db2e26e8bd1ad9486b65dce1292321eb3b37e [file] [log] [blame]
Pau Espin Pedrolc0a250d2021-01-21 18:46:13 +01001/* nacc_fsm.h
2 *
3 * Copyright (C) 2021 by sysmocom - s.f.m.c. GmbH <info@sysmocom.de>
4 * Author: Pau Espin Pedrol <pespin@sysmocom.de>
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
Pau Espin Pedrolc0a250d2021-01-21 18:46:13 +010015 */
16#pragma once
17
18#include <osmocom/core/fsm.h>
19#include <osmocom/gsm/gsm23003.h>
20
21#include <neigh_cache.h>
22
23struct GprsMs;
24struct gprs_rlcmac_tbf;
Pau Espin Pedrol106f2a02022-12-12 17:29:10 +010025struct gprs_rlcmac_pdch;
Pau Espin Pedrolc0a250d2021-01-21 18:46:13 +010026
27enum nacc_fsm_event {
28 NACC_EV_RX_CELL_CHG_NOTIFICATION, /* data: Packet_Cell_Change_Notification_t* */
Pau Espin Pedrol5557c0a2021-09-07 14:09:50 +020029 NACC_EV_RX_RAC_CI, /* RAC_CI became available in neigh_cache. NULL on failure, pointer to ctx->cgi_ps on success */
Pau Espin Pedrolc0a250d2021-01-21 18:46:13 +010030 NACC_EV_RX_SI, /* data: struct si_cache_entry* */
31 NACC_EV_CREATE_RLCMAC_MSG, /* data: struct nacc_ev_create_rlcmac_msg_ctx* */
Pau Espin Pedrol952cb3d2021-02-01 14:52:48 +010032 NACC_EV_RX_CELL_CHG_CONTINUE_ACK,
33 NACC_EV_TIMEOUT_CELL_CHG_CONTINUE, /* Poll Timeout */
Pau Espin Pedrolc0a250d2021-01-21 18:46:13 +010034};
35
36enum nacc_fsm_states {
37 NACC_ST_INITIAL,
38 NACC_ST_WAIT_RESOLVE_RAC_CI,
39 NACC_ST_WAIT_REQUEST_SI,
40 NACC_ST_TX_NEIGHBOUR_DATA,
41 NACC_ST_TX_CELL_CHG_CONTINUE,
Pau Espin Pedrol952cb3d2021-02-01 14:52:48 +010042 NACC_ST_WAIT_CELL_CHG_CONTINUE_ACK,
Pau Espin Pedrolc0a250d2021-01-21 18:46:13 +010043 NACC_ST_DONE,
44};
45
46struct nacc_fsm_ctx {
47 struct osmo_fsm_inst *fi;
48 struct GprsMs* ms; /* back pointer */
Pau Espin Pedrolc0a250d2021-01-21 18:46:13 +010049 struct neigh_cache_entry_key neigh_key; /* target cell info from MS */
50 struct osmo_cell_global_id_ps cgi_ps; /* target cell info resolved from req_{arfcn+bsic} */
51 struct si_cache_value si_info; /* SI info resolved from SGSN, to be sent to MS */
52 size_t si_info_bytes_sent; /* How many bytes out of si_info->si_len were already sent to MS */
53 size_t container_idx; /* Next container_idx to assign when sending Packet Neighbor Data message */
Pau Espin Pedrol952cb3d2021-02-01 14:52:48 +010054 uint32_t continue_poll_fn; /* Scheduled poll FN to CTRL ACK the Pkt Cell Chg Continue */
55 uint8_t continue_poll_ts; /* Scheduled poll TS to CTRL ACK the Pkt Cell Chg Continue */
Pau Espin Pedrolc0a250d2021-01-21 18:46:13 +010056};
57
58/* passed as data in NACC_EV_CREATE_RLCMAC_MSG */
59struct nacc_ev_create_rlcmac_msg_ctx {
60 struct gprs_rlcmac_tbf *tbf; /* target tbf to create messages for */
Pau Espin Pedrol5ba3ef92022-12-12 18:02:25 +010061 const struct gprs_rlcmac_pdch *pdch; /* TS where the created DL ctrl block is to be sent */
Pau Espin Pedrol952cb3d2021-02-01 14:52:48 +010062 uint32_t fn; /* FN where the created DL ctrl block is to be sent */
Pau Espin Pedrolc0a250d2021-01-21 18:46:13 +010063 struct msgb *msg; /* to be filled by FSM during event processing */
64};
65
66struct nacc_fsm_ctx *nacc_fsm_alloc(struct GprsMs* ms);
Pau Espin Pedrol5557c0a2021-09-07 14:09:50 +020067
68bool nacc_fsm_is_waiting_addr_resolution(const struct nacc_fsm_ctx *ctx,
69 const struct neigh_cache_entry_key *neigh_key);
Pau Espin Pedrol6c81add2021-09-07 14:43:46 +020070
71bool nacc_fsm_is_waiting_si_resolution(const struct nacc_fsm_ctx *ctx,
72 const struct osmo_cell_global_id_ps *cgi_ps);
Pau Espin Pedrolc276e492021-09-28 12:53:35 +020073
74bool nacc_fsm_exp_ctrl_ack(const struct nacc_fsm_ctx *ctx, uint32_t fn, uint8_t ts);
Pau Espin Pedrol106f2a02022-12-12 17:29:10 +010075
76bool tbf_nacc_rts(const struct gprs_rlcmac_tbf *tbf, const struct gprs_rlcmac_pdch *pdch);