From 16e706ecd4998e328ea31460ad547c29f6a3b335 Mon Sep 17 00:00:00 2001 From: Yoshihiro TSUBOI Date: Fri, 8 Jun 2018 20:13:58 +0900 Subject: [PATCH] [Wio 3G] Changed suggested points Changed accessibility cellular features member functions, fixed minor target issues --- .../framework/AT/AT_CellularNetwork.cpp | 25 ++++++++-------- .../framework/AT/AT_CellularNetwork.h | 4 +-- .../UG96/QUECTEL_UG96_CellularNetwork.cpp | 26 +++++++++++++++++ .../UG96/QUECTEL_UG96_CellularNetwork.h | 2 ++ .../TARGET_WIO_3G/PinNames.h | 29 ++----------------- targets/targets.json | 2 +- 6 files changed, 45 insertions(+), 43 deletions(-) diff --git a/features/cellular/framework/AT/AT_CellularNetwork.cpp b/features/cellular/framework/AT/AT_CellularNetwork.cpp index ffda83fa33..c95afff49e 100644 --- a/features/cellular/framework/AT/AT_CellularNetwork.cpp +++ b/features/cellular/framework/AT/AT_CellularNetwork.cpp @@ -243,7 +243,16 @@ nsapi_error_t AT_CellularNetwork::activate_context() { _at.lock(); - nsapi_error_t err = set_context_to_be_activated(); + nsapi_error_t err = NSAPI_ERROR_OK; + + // try to find or create context with suitable stack + if(get_context()) { + // try to authenticate user before activating or modifying context + err = do_user_authentication(); + } else { + err = NSAPI_ERROR_NO_CONNECTION; + } + if (err != NSAPI_ERROR_OK) { _at.unlock(); tr_error("Failed to activate network context! (%d)", err); @@ -420,7 +429,7 @@ void AT_CellularNetwork::ppp_status_cb(nsapi_event_t event, intptr_t parameter) } #endif -nsapi_error_t AT_CellularNetwork::set_context_to_be_activated() +nsapi_error_t AT_CellularNetwork::do_user_authentication() { // try to find or create context with suitable stack if (!get_context()) { @@ -429,21 +438,11 @@ nsapi_error_t AT_CellularNetwork::set_context_to_be_activated() // if user has defined user name and password we need to call CGAUTH before activating or modifying context if (_pwd && _uname) { -#if defined(TARGET_WIO_3G) - _at.cmd_start("AT+QICSGP="); - _at.write_int(_cid); - _at.write_int(1); // context type 1=IPv4 - _at.write_string(_apn); - _at.write_string(_uname); - _at.write_string(_pwd); - _at.write_int(_authentication_type); -#else _at.cmd_start("AT+CGAUTH="); _at.write_int(_cid); _at.write_int(_authentication_type); _at.write_string(_uname); _at.write_string(_pwd); -#endif _at.cmd_stop(); _at.resp_start(); _at.resp_stop(); @@ -452,7 +451,7 @@ nsapi_error_t AT_CellularNetwork::set_context_to_be_activated() } } - return _at.get_last_error(); + return NSAPI_ERROR_OK; } bool AT_CellularNetwork::set_new_context(int cid) diff --git a/features/cellular/framework/AT/AT_CellularNetwork.h b/features/cellular/framework/AT/AT_CellularNetwork.h index 7138b0f5d0..7cc57d59fd 100644 --- a/features/cellular/framework/AT/AT_CellularNetwork.h +++ b/features/cellular/framework/AT/AT_CellularNetwork.h @@ -149,13 +149,11 @@ private: void urc_cereg(); void urc_cgreg(); - nsapi_error_t set_context_to_be_activated(); nsapi_ip_stack_t string_to_stack_type(const char* pdp_type); void free_credentials(); nsapi_error_t open_data_channel(); - bool get_context(); bool set_new_context(int cid); nsapi_error_t delete_current_context(); @@ -180,6 +178,8 @@ protected: AuthenticationType _authentication_type; int _cell_id; nsapi_connection_status_t _connect_status; + virtual nsapi_error_t do_user_authentication(); + bool get_context(); bool _new_context_set; bool _is_context_active; RegistrationStatus _reg_status; diff --git a/features/cellular/framework/targets/QUECTEL/UG96/QUECTEL_UG96_CellularNetwork.cpp b/features/cellular/framework/targets/QUECTEL/UG96/QUECTEL_UG96_CellularNetwork.cpp index 17fa31a17d..3de1c5f9d0 100644 --- a/features/cellular/framework/targets/QUECTEL/UG96/QUECTEL_UG96_CellularNetwork.cpp +++ b/features/cellular/framework/targets/QUECTEL/UG96/QUECTEL_UG96_CellularNetwork.cpp @@ -42,3 +42,29 @@ nsapi_error_t QUECTEL_UG96_CellularNetwork::set_access_technology_impl(RadioAcce _op_act = RAT_UNKNOWN; return NSAPI_ERROR_UNSUPPORTED; } + +nsapi_error_t QUECTEL_UG96_CellularNetwork::do_user_authentication() +{ + // try to find or create context with suitable stack + if (!get_context()) { + return NSAPI_ERROR_NO_CONNECTION; + } + + if (_pwd && _uname) { + _at.cmd_start("AT+QICSGP="); + _at.write_int(_cid); + _at.write_int(1); // context type 1=IPv4 + _at.write_string(_apn); + _at.write_string(_uname); + _at.write_string(_pwd); + _at.write_int(_authentication_type); + _at.cmd_stop(); + _at.resp_start(); + _at.resp_stop(); + if (_at.get_last_error() != NSAPI_ERROR_OK) { + return NSAPI_ERROR_AUTH_FAILURE; + } + } + + return NSAPI_ERROR_OK; +} diff --git a/features/cellular/framework/targets/QUECTEL/UG96/QUECTEL_UG96_CellularNetwork.h b/features/cellular/framework/targets/QUECTEL/UG96/QUECTEL_UG96_CellularNetwork.h index f2f747fba6..5a0cd56a1f 100644 --- a/features/cellular/framework/targets/QUECTEL/UG96/QUECTEL_UG96_CellularNetwork.h +++ b/features/cellular/framework/targets/QUECTEL/UG96/QUECTEL_UG96_CellularNetwork.h @@ -34,6 +34,8 @@ protected: virtual bool has_registration(RegistrationType rat); virtual nsapi_error_t set_access_technology_impl(RadioAccessTechnology opRat); + + virtual nsapi_error_t do_user_authentication(); }; } // namespace mbed diff --git a/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F439xI/TARGET_WIO_3G/PinNames.h b/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F439xI/TARGET_WIO_3G/PinNames.h index d13c6ef232..1c5cb30be0 100644 --- a/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F439xI/TARGET_WIO_3G/PinNames.h +++ b/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F439xI/TARGET_WIO_3G/PinNames.h @@ -220,7 +220,7 @@ typedef enum { LED_RED = LED2, USER_BUTTON = PC_13, // Standardized button names -// BUTTON1 = USER_BUTTON, + BUTTON1 = PC_13, SERIAL_TX = STDIO_UART_TX, // Virtual Com Port SERIAL_RX = STDIO_UART_RX, // Virtual Com Port USBTX = STDIO_UART_TX, // Virtual Com Port @@ -229,33 +229,8 @@ typedef enum { SPI_MISO = PC_11, SPI_SCK = PC_10, SPI_CS = PD_0, -// PWM_OUT = D9, + PWM_OUT = D39, -/* - //USB pins - USB_OTG_HS_ULPI_D0 = PA_3, - USB_OTG_HS_SOF = PA_4, - USB_OTG_HS_ULPI_CK = PA_5, - USB_OTG_FS_SOF = PA_8, - USB_OTG_FS_VBUS = PA_9, - USB_OTG_FS_ID = PA_10, - USB_OTG_FS_DM = PA_11, - USB_OTG_FS_DP = PA_12, - USB_OTG_HS_ULPI_D1 = PB_0, - USB_OTG_HS_ULPI_D2 = PB_1, - USB_OTG_HS_ULPI_D7 = PB_5, - USB_OTG_HS_ULPI_D3 = PB_10, - USB_OTG_HS_ULPI_D4 = PB_11, - USB_OTG_HS_ID = PB_12, - USB_OTG_HS_ULPI_D5 = PB_12, - USB_OTG_HS_ULPI_D6 = PB_13, - USB_OTG_HS_VBUS = PB_13, - USB_OTG_HS_DM = PB_14, - USB_OTG_HS_DP = PB_15, - USB_OTG_HS_ULPI_STP = PC_0, - USB_OTG_HS_ULPI_DIR = PC_2, - USB_OTG_HS_ULPI_NXT = PC_3, -*/ // Not connected NC = (int)0xFFFFFFFF diff --git a/targets/targets.json b/targets/targets.json index 8eb4f4ac2d..abcfec64d1 100755 --- a/targets/targets.json +++ b/targets/targets.json @@ -1729,7 +1729,7 @@ "core": "Cortex-M4F", "config": { "clock_source": { - "help": "Mask value : USE_PLL_HSE_EXTC | USE_PLL_HSE_XTAL (need HW patch) | USE_PLL_HSI", + "help": "Mask value : USE_PLL_HSE_EXTC | USE_PLL_HSE_XTAL | USE_PLL_HSI", "value": "USE_PLL_HSE_XTAL|USE_PLL_HSI", "macro_name": "CLOCK_SOURCE" },