提交 1a5db09e 编写于 作者: M maosiping

use lwip

Signed-off-by: Nmaosiping <maosiping@huawei.com>
上级 4d734a94
...@@ -111,10 +111,9 @@ static int wsa_init_done = 0; ...@@ -111,10 +111,9 @@ static int wsa_init_done = 0;
#include <stdint.h> #include <stdint.h>
#ifdef LITEOS_VERSION #include "socket_compat.h"
#ifdef USE_LWIP
#include "lwip/sockets.h" #include "lwip/sockets.h"
#define close(fd) lwip_close(fd)
#define shutdown(fd, how) lwip_shutdown(fd, how)
#endif #endif
/* /*
...@@ -220,7 +219,11 @@ int mbedtls_net_connect( mbedtls_net_context *ctx, const char *host, ...@@ -220,7 +219,11 @@ int mbedtls_net_connect( mbedtls_net_context *ctx, const char *host,
break; break;
} }
#ifdef USE_LWIP
lwip_close(ctx->fd);
#else
close( ctx->fd ); close( ctx->fd );
#endif
ret = MBEDTLS_ERR_NET_CONNECT_FAILED; ret = MBEDTLS_ERR_NET_CONNECT_FAILED;
} }
...@@ -267,14 +270,22 @@ int mbedtls_net_bind( mbedtls_net_context *ctx, const char *bind_ip, const char ...@@ -267,14 +270,22 @@ int mbedtls_net_bind( mbedtls_net_context *ctx, const char *bind_ip, const char
if( setsockopt( ctx->fd, SOL_SOCKET, SO_REUSEADDR, if( setsockopt( ctx->fd, SOL_SOCKET, SO_REUSEADDR,
(const char *) &n, sizeof( n ) ) != 0 ) (const char *) &n, sizeof( n ) ) != 0 )
{ {
#ifdef USE_LWIP
lwip_close(ctx->fd);
#else
close( ctx->fd ); close( ctx->fd );
#endif
ret = MBEDTLS_ERR_NET_SOCKET_FAILED; ret = MBEDTLS_ERR_NET_SOCKET_FAILED;
continue; continue;
} }
if( bind( ctx->fd, cur->ai_addr, MSVC_INT_CAST cur->ai_addrlen ) != 0 ) if( bind( ctx->fd, cur->ai_addr, MSVC_INT_CAST cur->ai_addrlen ) != 0 )
{ {
#ifdef USE_LWIP
lwip_close(ctx->fd);
#else
close( ctx->fd ); close( ctx->fd );
#endif
ret = MBEDTLS_ERR_NET_BIND_FAILED; ret = MBEDTLS_ERR_NET_BIND_FAILED;
continue; continue;
} }
...@@ -284,7 +295,11 @@ int mbedtls_net_bind( mbedtls_net_context *ctx, const char *bind_ip, const char ...@@ -284,7 +295,11 @@ int mbedtls_net_bind( mbedtls_net_context *ctx, const char *bind_ip, const char
{ {
if( listen( ctx->fd, MBEDTLS_NET_LISTEN_BACKLOG ) != 0 ) if( listen( ctx->fd, MBEDTLS_NET_LISTEN_BACKLOG ) != 0 )
{ {
#ifdef USE_LWIP
lwip_close(ctx->fd);
#else
close( ctx->fd ); close( ctx->fd );
#endif
ret = MBEDTLS_ERR_NET_LISTEN_FAILED; ret = MBEDTLS_ERR_NET_LISTEN_FAILED;
continue; continue;
} }
...@@ -326,8 +341,12 @@ static int net_would_block( const mbedtls_net_context *ctx ) ...@@ -326,8 +341,12 @@ static int net_would_block( const mbedtls_net_context *ctx )
/* /*
* Never return 'WOULD BLOCK' on a blocking socket * Never return 'WOULD BLOCK' on a blocking socket
*/ */
#ifdef USE_LWIP
if ((lwip_fcntl(ctx->fd, F_GETFL, 0) & O_NONBLOCK) != O_NONBLOCK) {
#else
if( ( fcntl( ctx->fd, F_GETFL ) & O_NONBLOCK ) != O_NONBLOCK ) if( ( fcntl( ctx->fd, F_GETFL ) & O_NONBLOCK ) != O_NONBLOCK )
{ {
#endif
errno = err; errno = err;
return( 0 ); return( 0 );
} }
...@@ -474,8 +493,12 @@ int mbedtls_net_set_block( mbedtls_net_context *ctx ) ...@@ -474,8 +493,12 @@ int mbedtls_net_set_block( mbedtls_net_context *ctx )
!defined(EFI32) !defined(EFI32)
u_long n = 0; u_long n = 0;
return( ioctlsocket( ctx->fd, FIONBIO, &n ) ); return( ioctlsocket( ctx->fd, FIONBIO, &n ) );
#else
#ifdef USE_LWIP
return lwip_fcntl(ctx->fd, F_SETFL, lwip_fcntl(ctx->fd, F_GETFL, 0) & ~O_NONBLOCK);
#else #else
return( fcntl( ctx->fd, F_SETFL, fcntl( ctx->fd, F_GETFL ) & ~O_NONBLOCK ) ); return( fcntl( ctx->fd, F_SETFL, fcntl( ctx->fd, F_GETFL ) & ~O_NONBLOCK ) );
#endif // USE_LWIP
#endif #endif
} }
...@@ -485,8 +508,12 @@ int mbedtls_net_set_nonblock( mbedtls_net_context *ctx ) ...@@ -485,8 +508,12 @@ int mbedtls_net_set_nonblock( mbedtls_net_context *ctx )
!defined(EFI32) !defined(EFI32)
u_long n = 1; u_long n = 1;
return( ioctlsocket( ctx->fd, FIONBIO, &n ) ); return( ioctlsocket( ctx->fd, FIONBIO, &n ) );
#else
#ifdef USE_LWIP
return lwip_fcntl(ctx->fd, F_SETFL, lwip_fcntl(ctx->fd, F_GETFL, 0) | O_NONBLOCK);
#else #else
return( fcntl( ctx->fd, F_SETFL, fcntl( ctx->fd, F_GETFL ) | O_NONBLOCK ) ); return( fcntl( ctx->fd, F_SETFL, fcntl( ctx->fd, F_GETFL ) | O_NONBLOCK ) );
#endif // USE_LWIP
#endif #endif
} }
...@@ -712,8 +739,11 @@ void mbedtls_net_close( mbedtls_net_context *ctx ) ...@@ -712,8 +739,11 @@ void mbedtls_net_close( mbedtls_net_context *ctx )
{ {
if( ctx->fd == -1 ) if( ctx->fd == -1 )
return; return;
#ifdef USE_LWIP
lwip_close(ctx->fd);
#else
close( ctx->fd ); close( ctx->fd );
#endif
ctx->fd = -1; ctx->fd = -1;
} }
...@@ -725,9 +755,13 @@ void mbedtls_net_free( mbedtls_net_context *ctx ) ...@@ -725,9 +755,13 @@ void mbedtls_net_free( mbedtls_net_context *ctx )
{ {
if( ctx->fd == -1 ) if( ctx->fd == -1 )
return; return;
#ifdef USE_LWIP
lwip_shutdown(ctx->fd, 2);
lwip_close(ctx->fd);
#else
shutdown( ctx->fd, 2 ); shutdown( ctx->fd, 2 );
close( ctx->fd ); close( ctx->fd );
#endif
ctx->fd = -1; ctx->fd = -1;
} }
......
...@@ -139,3 +139,12 @@ if (defined(ohos_lite)) { ...@@ -139,3 +139,12 @@ if (defined(ohos_lite)) {
MBEDTLS_INLCUDE_DIRS += [ "$MBEDTLSDIR/port/include" ] MBEDTLS_INLCUDE_DIRS += [ "$MBEDTLSDIR/port/include" ]
} }
if (product_name == "generic_m55_arm_32_bes_aurora_wear_mini_application") {
MBEDTLS_INLCUDE_DIRS += [ "$MBEDTLSDIR/port/config/compat_lwip" ]
} else if (product_name ==
"generic_m55_arm_32_bes_phoinix_wear_mini_application") {
MBEDTLS_INLCUDE_DIRS += [ "$MBEDTLSDIR/port/config/compat_lwip" ]
} else {
MBEDTLS_INLCUDE_DIRS += [ "$MBEDTLSDIR/port/config/compat_posix" ]
}
/*
* Copyright (c) Huawei Technologies Co., Ltd. 2023. All rights reserved.
* 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.
*/
#ifndef MBED_TLS_SOCKET_COMPAT_H
#define MBED_TLS_SOCKET_COMPAT_H
#define USE_LWIP 1
#endif /* MBED_TLS_SOCKET_COMPAT_H */
/*
* Copyright (c) Huawei Technologies Co., Ltd. 2023. All rights reserved.
* 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.
*/
#ifndef MBED_TLS_SOCKET_COMPAT_H
#define MBED_TLS_SOCKET_COMPAT_H
#endif /* MBED_TLS_SOCKET_COMPAT_H */
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册