blob: b33dafa1cabf88c10be855beb18657e567c00053 [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;
25
26enum nacc_fsm_event {
27 NACC_EV_RX_CELL_CHG_NOTIFICATION, /* data: Packet_Cell_Change_Notification_t* */
Pau Espin Pedrol5557c0a2021-09-07 14:09:50 +020028 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 +010029 NACC_EV_RX_SI, /* data: struct si_cache_entry* */
30 NACC_EV_CREATE_RLCMAC_MSG, /* data: struct nacc_ev_create_rlcmac_msg_ctx* */
Pau Espin Pedrol952cb3d2021-02-01 14:52:48 +010031 NACC_EV_RX_CELL_CHG_CONTINUE_ACK,
32 NACC_EV_TIMEOUT_CELL_CHG_CONTINUE, /* Poll Timeout */
Pau Espin Pedrolc0a250d2021-01-21 18:46:13 +010033};
34
35enum nacc_fsm_states {
36 NACC_ST_INITIAL,
37 NACC_ST_WAIT_RESOLVE_RAC_CI,
38 NACC_ST_WAIT_REQUEST_SI,
39 NACC_ST_TX_NEIGHBOUR_DATA,
40 NACC_ST_TX_CELL_CHG_CONTINUE,
Pau Espin Pedrol952cb3d2021-02-01 14:52:48 +010041 NACC_ST_WAIT_CELL_CHG_CONTINUE_ACK,
Pau Espin Pedrolc0a250d2021-01-21 18:46:13 +010042 NACC_ST_DONE,
43};
44
45struct nacc_fsm_ctx {
46 struct osmo_fsm_inst *fi;
47 struct GprsMs* ms; /* back pointer */
48 struct ctrl_handle *neigh_ctrl;
49 struct ctrl_connection *neigh_ctrl_conn;
50 struct neigh_cache_entry_key neigh_key; /* target cell info from MS */
51 struct osmo_cell_global_id_ps cgi_ps; /* target cell info resolved from req_{arfcn+bsic} */
52 struct si_cache_value si_info; /* SI info resolved from SGSN, to be sent to MS */
53 size_t si_info_bytes_sent; /* How many bytes out of si_info->si_len were already sent to MS */
54 size_t container_idx; /* Next container_idx to assign when sending Packet Neighbor Data message */
Pau Espin Pedrol952cb3d2021-02-01 14:52:48 +010055 uint32_t continue_poll_fn; /* Scheduled poll FN to CTRL ACK the Pkt Cell Chg Continue */
56 uint8_t continue_poll_ts; /* Scheduled poll TS to CTRL ACK the Pkt Cell Chg Continue */
Pau Espin Pedrolc0a250d2021-01-21 18:46:13 +010057};
58
59/* passed as data in NACC_EV_CREATE_RLCMAC_MSG */
60struct nacc_ev_create_rlcmac_msg_ctx {
61 struct gprs_rlcmac_tbf *tbf; /* target tbf to create messages for */
Pau Espin Pedrol952cb3d2021-02-01 14:52:48 +010062 uint32_t fn; /* FN where the created DL ctrl block is to be sent */
63 uint8_t ts; /* TS where the created DL ctrl block is to be sent */
Pau Espin Pedrolc0a250d2021-01-21 18:46:13 +010064 struct msgb *msg; /* to be filled by FSM during event processing */
65};
66
67struct nacc_fsm_ctx *nacc_fsm_alloc(struct GprsMs* ms);
Pau Espin Pedrol5557c0a2021-09-07 14:09:50 +020068
69bool nacc_fsm_is_waiting_addr_resolution(const struct nacc_fsm_ctx *ctx,
70 const struct neigh_cache_entry_key *neigh_key);
Pau Espin Pedrol6c81add2021-09-07 14:43:46 +020071
72bool nacc_fsm_is_waiting_si_resolution(const struct nacc_fsm_ctx *ctx,
73 const struct osmo_cell_global_id_ps *cgi_ps);
Pau Espin Pedrolc276e492021-09-28 12:53:35 +020074
75bool nacc_fsm_exp_ctrl_ack(const struct nacc_fsm_ctx *ctx, uint32_t fn, uint8_t ts);