/* Configurations for modem */
int modem_configurations(void){
	char reply_buffer[64];
	char imei[25]; 

	// Modem configure 
	int err = modem_init();
	if (err) {
		LOG_ERR("Failed to configure the modem");
		return err;
	}

	// Enable modem events
	err = lte_lc_modem_events_enable();
	if(err != 0){
		LOG_ERR("lte_lc_modem_events_enable, err: %d", err);
	}

	// Register LTE event handler 
	lte_lc_register_handler(lte_lc_evt_handler);

	// Modem Info init 
	err = modem_info_init();
	if(err != 0){
		LOG_ERR("Failed to initialize the modem information module");
	}
	err = modem_info_params_init(&modem_param);
	if(err != 0){
		LOG_ERR("Failed to initialize the struture that stores information");
	}


	ntn_profile = (struct lte_lc_cellular_profile){
		.id = 0,
		.act = LTE_LC_ACT_NTN,
		.uicc = LTE_LC_UICC_PHYSICAL,
	};

	tn_profile = (struct lte_lc_cellular_profile){
		.id = 1,
		.act = LTE_LC_ACT_LTEM,
		.uicc = LTE_LC_UICC_PHYSICAL,
	};


	set_modem_func_mode(LTE_LC_FUNC_MODE_POWER_OFF);
	set_modem_system_mode(LTE_LC_SYSTEM_MODE_NTN_NBIOT, LTE_LC_SYSTEM_MODE_PREFER_AUTO);
	

	// Set locked bands
	err = nrf_modem_at_printf("AT%%XBANDLOCK=2,,\"23,255,256,20,8\"");
	if (err) {
		LOG_ERR("Failed to set NTN band lock, error: %d", err);
		return err;
	}

	// Set NTN profile (index = 0) 
	err = lte_lc_cellular_profile_configure(&ntn_profile);
	if (err) {
		LOG_ERR("Failed to set NTN profile, error: %d", err);
		return err;
	}

	// Set TN profile (index = 1) 
	err = lte_lc_cellular_profile_configure(&tn_profile);
	if (err) {
		LOG_ERR("Failed to set TN profile, error: %d", err);
		return err;
	}

	// Register handler for default PDP context 0
	err = lte_lc_pdn_default_ctx_events_enable();
	if (err) {
		LOG_ERR("lte_lc_pdn_default_ctx_events_enable, error: %d", err);
		return err;
	}

	return 0;
}


int pdn_configuration(void)
{
	int err;

	// (CID = (cid 0...9) + 10 * profile_index)
	uint8_t cid_tn = 10, cid_ntn = 0;  
	
	err = lte_lc_pdn_ctx_configure(cid_tn, apn, LTE_LC_PDN_FAM_IPV4, NULL);
	if (err) {
		LOG_ERR("Error to configure CID_TN: %d", err);
		return err;
	}

	err = lte_lc_pdn_ctx_configure(cid_ntn, apn, LTE_LC_PDN_FAM_IPV4, NULL);
	if (err) {
		LOG_ERR("Error to configure CID_NTN: %d", err);
		return err;
	}

	return err;
}