Pau Espin Pedrol | c0a250d | 2021-01-21 18:46:13 +0100 | [diff] [blame] | 1 | /* 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. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 19 | */ |
| 20 | #pragma once |
| 21 | |
| 22 | #include <osmocom/core/fsm.h> |
| 23 | #include <osmocom/gsm/gsm23003.h> |
| 24 | |
| 25 | #include <neigh_cache.h> |
| 26 | |
| 27 | struct GprsMs; |
| 28 | struct gprs_rlcmac_tbf; |
| 29 | |
| 30 | enum nacc_fsm_event { |
| 31 | NACC_EV_RX_CELL_CHG_NOTIFICATION, /* data: Packet_Cell_Change_Notification_t* */ |
Pau Espin Pedrol | 5557c0a | 2021-09-07 14:09:50 +0200 | [diff] [blame] | 32 | NACC_EV_RX_RAC_CI, /* RAC_CI became available in neigh_cache. NULL on failure, pointer to ctx->cgi_ps on success */ |
Pau Espin Pedrol | c0a250d | 2021-01-21 18:46:13 +0100 | [diff] [blame] | 33 | NACC_EV_RX_SI, /* data: struct si_cache_entry* */ |
| 34 | NACC_EV_CREATE_RLCMAC_MSG, /* data: struct nacc_ev_create_rlcmac_msg_ctx* */ |
Pau Espin Pedrol | 952cb3d | 2021-02-01 14:52:48 +0100 | [diff] [blame] | 35 | NACC_EV_RX_CELL_CHG_CONTINUE_ACK, |
| 36 | NACC_EV_TIMEOUT_CELL_CHG_CONTINUE, /* Poll Timeout */ |
Pau Espin Pedrol | c0a250d | 2021-01-21 18:46:13 +0100 | [diff] [blame] | 37 | }; |
| 38 | |
| 39 | enum nacc_fsm_states { |
| 40 | NACC_ST_INITIAL, |
| 41 | NACC_ST_WAIT_RESOLVE_RAC_CI, |
| 42 | NACC_ST_WAIT_REQUEST_SI, |
| 43 | NACC_ST_TX_NEIGHBOUR_DATA, |
| 44 | NACC_ST_TX_CELL_CHG_CONTINUE, |
Pau Espin Pedrol | 952cb3d | 2021-02-01 14:52:48 +0100 | [diff] [blame] | 45 | NACC_ST_WAIT_CELL_CHG_CONTINUE_ACK, |
Pau Espin Pedrol | c0a250d | 2021-01-21 18:46:13 +0100 | [diff] [blame] | 46 | NACC_ST_DONE, |
| 47 | }; |
| 48 | |
| 49 | struct nacc_fsm_ctx { |
| 50 | struct osmo_fsm_inst *fi; |
| 51 | struct GprsMs* ms; /* back pointer */ |
| 52 | struct ctrl_handle *neigh_ctrl; |
| 53 | struct ctrl_connection *neigh_ctrl_conn; |
| 54 | struct neigh_cache_entry_key neigh_key; /* target cell info from MS */ |
| 55 | struct osmo_cell_global_id_ps cgi_ps; /* target cell info resolved from req_{arfcn+bsic} */ |
| 56 | struct si_cache_value si_info; /* SI info resolved from SGSN, to be sent to MS */ |
| 57 | size_t si_info_bytes_sent; /* How many bytes out of si_info->si_len were already sent to MS */ |
| 58 | size_t container_idx; /* Next container_idx to assign when sending Packet Neighbor Data message */ |
Pau Espin Pedrol | 952cb3d | 2021-02-01 14:52:48 +0100 | [diff] [blame] | 59 | uint32_t continue_poll_fn; /* Scheduled poll FN to CTRL ACK the Pkt Cell Chg Continue */ |
| 60 | uint8_t continue_poll_ts; /* Scheduled poll TS to CTRL ACK the Pkt Cell Chg Continue */ |
Pau Espin Pedrol | c0a250d | 2021-01-21 18:46:13 +0100 | [diff] [blame] | 61 | }; |
| 62 | |
| 63 | /* passed as data in NACC_EV_CREATE_RLCMAC_MSG */ |
| 64 | struct nacc_ev_create_rlcmac_msg_ctx { |
| 65 | struct gprs_rlcmac_tbf *tbf; /* target tbf to create messages for */ |
Pau Espin Pedrol | 952cb3d | 2021-02-01 14:52:48 +0100 | [diff] [blame] | 66 | uint32_t fn; /* FN where the created DL ctrl block is to be sent */ |
| 67 | uint8_t ts; /* TS where the created DL ctrl block is to be sent */ |
Pau Espin Pedrol | c0a250d | 2021-01-21 18:46:13 +0100 | [diff] [blame] | 68 | struct msgb *msg; /* to be filled by FSM during event processing */ |
| 69 | }; |
| 70 | |
| 71 | struct nacc_fsm_ctx *nacc_fsm_alloc(struct GprsMs* ms); |
Pau Espin Pedrol | 5557c0a | 2021-09-07 14:09:50 +0200 | [diff] [blame] | 72 | |
| 73 | bool nacc_fsm_is_waiting_addr_resolution(const struct nacc_fsm_ctx *ctx, |
| 74 | const struct neigh_cache_entry_key *neigh_key); |
Pau Espin Pedrol | 6c81add | 2021-09-07 14:43:46 +0200 | [diff] [blame] | 75 | |
| 76 | bool nacc_fsm_is_waiting_si_resolution(const struct nacc_fsm_ctx *ctx, |
| 77 | const struct osmo_cell_global_id_ps *cgi_ps); |
Pau Espin Pedrol | c276e49 | 2021-09-28 12:53:35 +0200 | [diff] [blame] | 78 | |
| 79 | bool nacc_fsm_exp_ctrl_ack(const struct nacc_fsm_ctx *ctx, uint32_t fn, uint8_t ts); |