1515#include "nrf_cloud_coap_transport.h"
1616#include <modem/at_parser.h>
1717#include <modem/nrf_modem_lib.h>
18- #include <modem/modem_info.h>
1918#include "sm_util.h"
2019#include "sm_at_host.h"
2120#include "sm_at_nrfcloud.h"
@@ -81,6 +80,11 @@ static struct lte_lc_cells_info *nrfcloud_cell_data;
8180/* nRF Cloud location request Wi-Fi data. */
8281static struct wifi_scan_info nrfcloud_wifi_data ;
8382
83+ /**
84+ * Waiting time (in seconds) of RRC connection going into idle mode. Because GCI search
85+ * cannot scan GCI cells during RRC connected mode, we will wait for the RRC idle mode before
86+ * initiating GCI search.
87+ */
8488#define SCAN_CELLULAR_RRC_IDLE_WAIT_TIME 10
8589
8690static K_SEM_DEFINE (entered_rrc_idle , 1 , 1 ) ;
@@ -236,7 +240,7 @@ static int handle_at_nrf_cloud(enum at_parser_cmd_type cmd_type, struct at_parse
236240 k_work_submit_to_queue (& sm_work_q , & nrfcloud_conn_work );
237241 err = 0 ;
238242 } else {
239- err = - EINVAL ;
243+ err = - EBUSY ;
240244 } break ;
241245
242246 case AT_PARSER_CMD_TYPE_READ : {
@@ -411,7 +415,7 @@ static int handle_at_nrf_cloud_pos(enum at_parser_cmd_type cmd_type,
411415
412416 nrfcloud_sending_loc_req = true;
413417 if (cell_count >= 1 ) {
414- scan_cellular_execute (cell_count );
418+ scan_cellular_execute (cell_count , NULL );
415419 } else {
416420 k_work_submit_to_queue (& sm_work_q , & nrfcloud_loc_req_work );
417421 }
@@ -510,20 +514,22 @@ static void cleanup_nrfcloud_cell_data(void)
510514 nrfcloud_cell_data = NULL ;
511515}
512516
513- void scan_cellular_execute (uint8_t cell_count )
517+ void scan_cellular_execute (uint8_t cell_count , struct lte_lc_cells_info * cell_data )
514518{
515519 int err ;
516520 uint8_t ncellmeas3_cell_count ;
517521
518- /* Allocate main cell data structure.
519- * Neighbor cells structure is only allocated when they are found.
520- */
521- nrfcloud_cell_data = calloc (1 , sizeof (struct lte_lc_cells_info ));
522- if (nrfcloud_cell_data == NULL ) {
523- LOG_ERR ("Failed to allocate memory for the nRF Cloud cell data" );
524- return ;
522+ nrfcloud_cell_data = cell_data ;
523+ if (cell_data == NULL ) {
524+ /* Allocate main cell data structure.
525+ * Neighbor cells structure is only allocated when they are found.
526+ */
527+ nrfcloud_cell_data = calloc (1 , sizeof (struct lte_lc_cells_info ));
528+ if (nrfcloud_cell_data == NULL ) {
529+ LOG_ERR ("Failed to allocate memory for the nRF Cloud cell data" );
530+ return ;
531+ }
525532 }
526-
527533 nrfcloud_cell_data -> current_cell .id = LTE_LC_CELL_EUTRAN_ID_INVALID ;
528534 nrfcloud_cell_data -> ncells_count = 0 ;
529535 nrfcloud_cell_data -> gci_cells_count = 0 ;
@@ -640,7 +646,8 @@ void scan_cellular_execute(uint8_t cell_count)
640646 at_monitor_pause (& sm_ncellmeas );
641647 if (err == 0 ) {
642648 k_work_submit_to_queue (& sm_work_q , & nrfcloud_loc_req_work );
643- } else {
649+ } else if (cell_data == NULL ) {
650+ /* If cell_data is not provided, cleanup the cell data in error cases */
644651 cleanup_nrfcloud_cell_data ();
645652 }
646653 k_work_cancel_delayable (& scan_cellular_timeout_backup_work );
@@ -653,31 +660,6 @@ static void scan_cellular_timeout_backup_work_fn(struct k_work *work)
653660 k_sem_reset (& scan_cellular_sem_ncellmeas_evt );
654661}
655662
656- /* TODO: Remove use of modem info completely */
657- int get_single_cell_info (struct lte_lc_cell * const cell_inf )
658- {
659- int err ;
660- struct modem_param_info modem_inf ;
661-
662- err = modem_info_params_init (& modem_inf );
663- if (err ) {
664- LOG_ERR ("Could not initialize modem info module, error: %d" , err );
665- return err ;
666- }
667- err = modem_info_params_get (& modem_inf );
668- if (err ) {
669- LOG_ERR ("Could not obtain information from modem, error: %d" , err );
670- return err ;
671- }
672- cell_inf -> mcc = modem_inf .network .mcc .value ;
673- cell_inf -> mnc = modem_inf .network .mnc .value ;
674- cell_inf -> tac = modem_inf .network .area_code .value ;
675- cell_inf -> id = modem_inf .network .cellid_dec ;
676- cell_inf -> rsrp = modem_inf .network .rsrp .value ;
677-
678- return 0 ;
679- }
680-
681663static void nrfcloud_loc_req_work_fn (struct k_work * work )
682664{
683665 int err = 0 ;
0 commit comments