Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cypress: Backport PRs from 6.0 to 5.15.2 #12753

Merged
merged 10 commits into from
Apr 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
3 changes: 2 additions & 1 deletion TESTS/mbed_hal/qspi/flash_configs/flash_configs.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@
defined(TARGET_CY8CPROTO_062S2_43012) || \
defined(TARGET_CY8CPROTO_062S3_4343W) || \
defined(TARGET_CYW943012P6EVB_01) || \
defined(TARGET_CYW9P62S1_43438EVB_01))
defined(TARGET_CYW9P62S1_43438EVB_01) || \
defined(TARGET_CYSBSYSKIT_01))
#include "S25FL512S_config.h"

#elif defined(TARGET_CYW9P62S1_43012EVB_01)
Expand Down
3 changes: 3 additions & 0 deletions TESTS/mbed_hal_fpga_ci_test_shield/uart/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@ static void uart_test_common(int baudrate, int data_bits, SerialParity parity, i
serial_set_flow_control_direct(&serial, FlowControlRTSCTS, &pinmap);
#else
//skip this test case if static pinmap is not supported
// Cleanup uart to be able execute next test case
serial_free(&serial);
tester.reset();
return;
#endif
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

/* labelling: appname-(chipname)(stepping)-frequency-(headset GIT SHA)-(generating SDK version)-
* Wiced-release.hcd */
#ifndef TARGET_CYW9P62S1_43012EVB_01
const char brcm_patch_version[] = "CYW43012C0_003.001.015.0128.0000_Generic_UART_37_4MHz_wlcsp_ref3_sLNA";
const uint8_t brcm_patchram_format = 0x01;
/* Configuration Data Records (Write_RAM) */
Expand Down Expand Up @@ -4061,3 +4062,4 @@ const uint8_t brcm_patchram_buf[] = {
};

const int brcm_patch_ram_length = sizeof(brcm_patchram_buf);
#endif

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,328 @@
/*
* Copyright 2018-2020 Cypress Semiconductor Corporation
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include <cstring>
#include <algorithm>
#include <vector>
#include "SclSTAInterface.h"
#include "nsapi.h"
#include "lwipopts.h"
#include "lwip/etharp.h"
#include "lwip/ethip6.h"
#include "rtos.h"
#include "scl_emac.h"
#include "scl_ipc.h"
#include "mbed_wait_api.h"


/** @file
* Provides SCL interface functions to be used with WiFiInterface or NetworkInterface Objects
*/

struct scl_tx_nw_credentials {
nsapi_security_t network_security_type;
int ssid_len;
int pass_len;
const char *network_ssid;
const char *network_passphrase;
} scl_tx_nw_credentials_t;

network_params_t network_parameter;

int scl_toerror(scl_result_t res)
{
switch (res) {
case SCL_SUCCESS:
return NSAPI_ERROR_OK;
case SCL_UNSUPPORTED:
return NSAPI_ERROR_UNSUPPORTED;
case SCL_BADARG:
return NSAPI_ERROR_PARAMETER;
case SCL_INVALID_JOIN_STATUS:
return NSAPI_ERROR_NO_CONNECTION;
case SCL_BUFFER_UNAVAILABLE_PERMANENT:
case SCL_BUFFER_UNAVAILABLE_TEMPORARY:
case SCL_RX_BUFFER_ALLOC_FAIL:
case SCL_BUFFER_ALLOC_FAIL:
case SCL_MALLOC_FAILURE:
return NSAPI_ERROR_NO_MEMORY;
case SCL_ACCESS_POINT_NOT_FOUND:
case SCL_NETWORK_NOT_FOUND:
return NSAPI_ERROR_NO_SSID;
case SCL_NOT_AUTHENTICATED:
case SCL_INVALID_KEY:
case SCL_NOT_KEYED:
return NSAPI_ERROR_AUTH_FAILURE;
case SCL_PENDING:
case SCL_JOIN_IN_PROGRESS:
return NSAPI_ERROR_IN_PROGRESS;
case SCL_CONNECTION_LOST:
return NSAPI_ERROR_CONNECTION_LOST;
case SCL_TIMEOUT:
case SCL_EAPOL_KEY_PACKET_M1_TIMEOUT:
case SCL_EAPOL_KEY_PACKET_M3_TIMEOUT:
case SCL_EAPOL_KEY_PACKET_G1_TIMEOUT:
return NSAPI_ERROR_CONNECTION_TIMEOUT;
default:
return -res;
}
}

nsapi_security_t scl_tosecurity(scl_security_t sec)
{
switch (sec) {
case SCL_SECURITY_OPEN:
return NSAPI_SECURITY_NONE;
case SCL_SECURITY_WEP_PSK:
case SCL_SECURITY_WEP_SHARED:
return NSAPI_SECURITY_WEP;
case SCL_SECURITY_WPA_TKIP_PSK:
case SCL_SECURITY_WPA_TKIP_ENT:
return NSAPI_SECURITY_WPA;
case SCL_SECURITY_WPA2_MIXED_PSK:
return NSAPI_SECURITY_WPA_WPA2;
case SCL_SECURITY_WPA2_AES_PSK:
case SCL_SECURITY_WPA2_AES_ENT:
case SCL_SECURITY_WPA2_FBT_PSK:
case SCL_SECURITY_WPA2_FBT_ENT:
return NSAPI_SECURITY_WPA2;
default:
return NSAPI_SECURITY_UNKNOWN;
}
}

scl_security_t scl_fromsecurity(nsapi_security_t sec)
{
switch (sec) {
case NSAPI_SECURITY_NONE:
return SCL_SECURITY_OPEN;
case NSAPI_SECURITY_WEP:
return SCL_SECURITY_WEP_PSK;
case NSAPI_SECURITY_WPA:
return SCL_SECURITY_WPA_MIXED_PSK;
case NSAPI_SECURITY_WPA2:
return SCL_SECURITY_WPA2_AES_PSK;
case NSAPI_SECURITY_WPA_WPA2:
return SCL_SECURITY_WPA2_MIXED_PSK;
default:
return SCL_SECURITY_UNKNOWN;
}
}

SclSTAInterface::SclSTAInterface(SCL_EMAC &emac, OnboardNetworkStack &stack)
: EMACInterface(emac, stack),
_ssid("\0"),
_pass("\0"),
_security(NSAPI_SECURITY_NONE),
_scl_emac(emac)
{
}

nsapi_error_t SclSTAInterface::connect(const char *ssid, const char *pass, nsapi_security_t security, uint8_t channel)
{
int err = set_channel(channel);
if (err) {
return err;
}

err = set_credentials(ssid, pass, security);
if (err) {
return err;
}

return connect();
}

nsapi_error_t SclSTAInterface::set_credentials(const char *ssid, const char *pass, nsapi_security_t security)
{
if ((ssid == NULL) ||
(strlen(ssid) == 0) ||
(pass == NULL && (security != NSAPI_SECURITY_NONE)) ||
(strlen(pass) == 0 && (security != NSAPI_SECURITY_NONE)) ||
(strlen(pass) > 63 && (security == NSAPI_SECURITY_WPA2 || security == NSAPI_SECURITY_WPA || security == NSAPI_SECURITY_WPA_WPA2))
) {
return NSAPI_ERROR_PARAMETER;
}

memset(_ssid, 0, sizeof(_ssid));
strncpy(_ssid, ssid, sizeof(_ssid));

memset(_pass, 0, sizeof(_pass));
strncpy(_pass, pass, sizeof(_pass));

_security = security;

return NSAPI_ERROR_OK;
}

nsapi_error_t SclSTAInterface::connect()
{

uint32_t delay_timeout = 0;
scl_result_t ret_val;
nsapi_error_t interface_status;
uint32_t connection_status = 0;

scl_tx_nw_credentials_t.network_ssid = _ssid;
if (strlen(_ssid) < MAX_SSID_LENGTH) {
scl_tx_nw_credentials_t.ssid_len = strlen(_ssid);
}
scl_tx_nw_credentials_t.network_passphrase = _pass;
if (strlen(_pass) < MAX_PASSWORD_LENGTH) {
scl_tx_nw_credentials_t.pass_len = strlen(_pass);
}
scl_tx_nw_credentials_t.network_security_type = _security;

ret_val = scl_send_data(SCL_TX_CONNECT, (char *)&scl_tx_nw_credentials_t, TIMER_DEFAULT_VALUE);

if (ret_val == SCL_SUCCESS) {
SCL_LOG(("wifi provisioning in progress"));
}

network_parameter.connection_status = NSAPI_STATUS_DISCONNECTED;


//Get the network parameter from NP
while ((network_parameter.connection_status != NSAPI_STATUS_GLOBAL_UP) && delay_timeout < NW_CONNECT_TIMEOUT) {
ret_val = scl_get_nw_parameters(&network_parameter);
wait_us(NW_DELAY_TIME_US);
delay_timeout++;
}

if (delay_timeout >= NW_CONNECT_TIMEOUT || ret_val != SCL_SUCCESS) {
return NSAPI_ERROR_NO_CONNECTION;
}

if (!_scl_emac.powered_up) {
_scl_emac.power_up();
}

if (!_interface) {
nsapi_error_t err = _stack.add_ethernet_interface(_emac, true, &_interface);
if (err != NSAPI_ERROR_OK) {
_interface = NULL;
return err;
}
_interface->attach(_connection_status_cb);
}

if (!scl_wifi_is_ready_to_transceive()) {
scl_emac_wifi_link_state_changed(true);
}

interface_status = _interface->bringup(false,
network_parameter.ip_address,
network_parameter.netmask,
network_parameter.gateway,
DEFAULT_STACK);

scl_send_data(SCL_TX_CONNECTION_STATUS, (char *)&connection_status, TIMER_DEFAULT_VALUE);

return interface_status;
}

void SclSTAInterface::wifi_on()
{
if (!_scl_emac.powered_up) {
_scl_emac.power_up();
}
}

nsapi_error_t SclSTAInterface::disconnect()
{
scl_result_t ret_val;
nsapi_error_t disconnect_status;
ret_val = scl_send_data(SCL_TX_DISCONNECT, (char *)&disconnect_status, TIMER_DEFAULT_VALUE);

if (ret_val == SCL_ERROR) {
return NSAPI_ERROR_TIMEOUT;
}

if (!_interface) {
return NSAPI_STATUS_DISCONNECTED;
}

// bring down
int err = _interface->bringdown();
if (err) {
return err;
}

scl_emac_wifi_link_state_changed(false);

return NSAPI_ERROR_OK;
}

int SclSTAInterface::scan(WiFiAccessPoint *res, unsigned count)
{
/* To Do */
return NSAPI_ERROR_UNSUPPORTED;
}

int8_t SclSTAInterface::get_rssi()
{
int32_t rssi;
scl_result_t res;

if (!_scl_emac.powered_up) {
_scl_emac.power_up();
}

res = (scl_result_t) scl_wifi_get_rssi(&rssi);
if (res == SCL_ERROR) {
return SCL_ERROR;
}

return (int8_t)rssi;
}

int SclSTAInterface::is_interface_connected(void)
{
if (scl_wifi_is_ready_to_transceive() == SCL_SUCCESS) {
return SCL_SUCCESS;
} else {
return SCL_CONNECTION_LOST;
}
}

int SclSTAInterface::get_bssid(uint8_t *bssid)
{
scl_mac_t ap_mac;
scl_result_t res = SCL_SUCCESS;

if (bssid == NULL) {
return SCL_BADARG;
}

memset(&ap_mac, 0, sizeof(ap_mac));
if (scl_wifi_is_ready_to_transceive() == SCL_SUCCESS) {
res = (scl_result_t) scl_wifi_get_bssid(&ap_mac);
if (res == SCL_SUCCESS) {
memcpy(bssid, ap_mac.octet, sizeof(ap_mac.octet));
}
} else {
return SCL_CONNECTION_LOST;
}
return res;
}

int SclSTAInterface::wifi_set_up(void)
{
int res = SCL_SUCCESS;
res = scl_wifi_set_up();
return res;
}
Loading