Skip to content

Commit 9d2bf9c

Browse files
committed
drivers, wiznet5k: Wrap exported functions in a macro for renaming.
3rd party drivers should not export generic names like "close".
1 parent 3a1c4c5 commit 9d2bf9c

File tree

4 files changed

+53
-50
lines changed

4 files changed

+53
-50
lines changed

drivers/wiznet5k/ethernet/socket.c

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ static uint8_t sock_pack_info[_WIZCHIP_SOCK_NUM_] = {0,};
8787

8888

8989

90-
int8_t socket(uint8_t sn, uint8_t protocol, uint16_t port, uint8_t flag)
90+
int8_t WIZCHIP_EXPORT(socket)(uint8_t sn, uint8_t protocol, uint16_t port, uint8_t flag)
9191
{
9292
CHECK_SOCKNUM();
9393
switch(protocol)
@@ -132,7 +132,7 @@ int8_t socket(uint8_t sn, uint8_t protocol, uint16_t port, uint8_t flag)
132132
break;
133133
}
134134
}
135-
close(sn);
135+
WIZCHIP_EXPORT(close)(sn);
136136
setSn_MR(sn, (protocol | (flag & 0xF0)));
137137
if(!port)
138138
{
@@ -150,7 +150,7 @@ int8_t socket(uint8_t sn, uint8_t protocol, uint16_t port, uint8_t flag)
150150
return (int8_t)sn;
151151
}
152152

153-
int8_t close(uint8_t sn)
153+
int8_t WIZCHIP_EXPORT(close)(uint8_t sn)
154154
{
155155
CHECK_SOCKNUM();
156156

@@ -166,7 +166,7 @@ int8_t close(uint8_t sn)
166166
return SOCK_OK;
167167
}
168168

169-
int8_t listen(uint8_t sn)
169+
int8_t WIZCHIP_EXPORT(listen)(uint8_t sn)
170170
{
171171
CHECK_SOCKNUM();
172172
CHECK_SOCKMODE(Sn_MR_TCP);
@@ -177,15 +177,15 @@ int8_t listen(uint8_t sn)
177177
{
178178
if(getSn_CR(sn) == SOCK_CLOSED)
179179
{
180-
close(sn);
180+
WIZCHIP_EXPORT(close)(sn);
181181
return SOCKERR_SOCKCLOSED;
182182
}
183183
}
184184
return SOCK_OK;
185185
}
186186

187187

188-
int8_t connect(uint8_t sn, uint8_t * addr, uint16_t port)
188+
int8_t WIZCHIP_EXPORT(connect)(uint8_t sn, uint8_t * addr, uint16_t port)
189189
{
190190
CHECK_SOCKNUM();
191191
CHECK_SOCKMODE(Sn_MR_TCP);
@@ -236,7 +236,7 @@ int8_t connect(uint8_t sn, uint8_t * addr, uint16_t port)
236236
return SOCK_OK;
237237
}
238238

239-
int8_t disconnect(uint8_t sn)
239+
int8_t WIZCHIP_EXPORT(disconnect)(uint8_t sn)
240240
{
241241
CHECK_SOCKNUM();
242242
CHECK_SOCKMODE(Sn_MR_TCP);
@@ -249,14 +249,14 @@ int8_t disconnect(uint8_t sn)
249249
{
250250
if(getSn_IR(sn) & Sn_IR_TIMEOUT)
251251
{
252-
close(sn);
252+
WIZCHIP_EXPORT(close)(sn);
253253
return SOCKERR_TIMEOUT;
254254
}
255255
}
256256
return SOCK_OK;
257257
}
258258

259-
int32_t send(uint8_t sn, uint8_t * buf, uint16_t len)
259+
int32_t WIZCHIP_EXPORT(send)(uint8_t sn, uint8_t * buf, uint16_t len)
260260
{
261261
uint8_t tmp=0;
262262
uint16_t freesize=0;
@@ -284,7 +284,7 @@ int32_t send(uint8_t sn, uint8_t * buf, uint16_t len)
284284
}
285285
else if(tmp & Sn_IR_TIMEOUT)
286286
{
287-
close(sn);
287+
WIZCHIP_EXPORT(close)(sn);
288288
return SOCKERR_TIMEOUT;
289289
}
290290
else return SOCK_BUSY;
@@ -297,7 +297,7 @@ int32_t send(uint8_t sn, uint8_t * buf, uint16_t len)
297297
tmp = getSn_SR(sn);
298298
if ((tmp != SOCK_ESTABLISHED) && (tmp != SOCK_CLOSE_WAIT))
299299
{
300-
close(sn);
300+
WIZCHIP_EXPORT(close)(sn);
301301
return SOCKERR_SOCKSTATUS;
302302
}
303303
if( (sock_io_mode & (1<<sn)) && (len > freesize) ) return SOCK_BUSY;
@@ -315,7 +315,7 @@ int32_t send(uint8_t sn, uint8_t * buf, uint16_t len)
315315
}
316316

317317

318-
int32_t recv(uint8_t sn, uint8_t * buf, uint16_t len)
318+
int32_t WIZCHIP_EXPORT(recv)(uint8_t sn, uint8_t * buf, uint16_t len)
319319
{
320320
uint8_t tmp = 0;
321321
uint16_t recvsize = 0;
@@ -336,13 +336,13 @@ int32_t recv(uint8_t sn, uint8_t * buf, uint16_t len)
336336
if(recvsize != 0) break;
337337
else if(getSn_TX_FSR(sn) == getSn_TxMAX(sn))
338338
{
339-
close(sn);
339+
WIZCHIP_EXPORT(close)(sn);
340340
return SOCKERR_SOCKSTATUS;
341341
}
342342
}
343343
else
344344
{
345-
close(sn);
345+
WIZCHIP_EXPORT(close)(sn);
346346
return SOCKERR_SOCKSTATUS;
347347
}
348348
}
@@ -357,7 +357,7 @@ int32_t recv(uint8_t sn, uint8_t * buf, uint16_t len)
357357
return len;
358358
}
359359

360-
int32_t sendto(uint8_t sn, uint8_t * buf, uint16_t len, uint8_t * addr, uint16_t port)
360+
int32_t WIZCHIP_EXPORT(sendto)(uint8_t sn, uint8_t * buf, uint16_t len, uint8_t * addr, uint16_t port)
361361
{
362362
uint8_t tmp = 0;
363363
uint16_t freesize = 0;
@@ -436,7 +436,7 @@ int32_t sendto(uint8_t sn, uint8_t * buf, uint16_t len, uint8_t * addr, uint16_t
436436

437437

438438

439-
int32_t recvfrom(uint8_t sn, uint8_t * buf, uint16_t len, uint8_t * addr, uint16_t *port)
439+
int32_t WIZCHIP_EXPORT(recvfrom)(uint8_t sn, uint8_t * buf, uint16_t len, uint8_t * addr, uint16_t *port)
440440
{
441441
uint8_t mr;
442442
uint8_t head[8];
@@ -506,7 +506,7 @@ int32_t recvfrom(uint8_t sn, uint8_t * buf, uint16_t len, uint8_t * addr, uint16
506506
sock_remained_size[sn] = (sock_remained_size[sn] <<8) + head[1];
507507
if(sock_remained_size[sn] > 1514)
508508
{
509-
close(sn);
509+
WIZCHIP_EXPORT(close)(sn);
510510
return SOCKFATAL_PACKLEN;
511511
}
512512
sock_pack_info[sn] = PACK_FIRST;
@@ -555,7 +555,7 @@ int32_t recvfrom(uint8_t sn, uint8_t * buf, uint16_t len, uint8_t * addr, uint16
555555
}
556556

557557

558-
int8_t ctlsocket(uint8_t sn, ctlsock_type cstype, void* arg)
558+
int8_t WIZCHIP_EXPORT(ctlsocket)(uint8_t sn, ctlsock_type cstype, void* arg)
559559
{
560560
uint8_t tmp = 0;
561561
CHECK_SOCKNUM();
@@ -598,7 +598,7 @@ int8_t ctlsocket(uint8_t sn, ctlsock_type cstype, void* arg)
598598
return SOCK_OK;
599599
}
600600

601-
int8_t setsockopt(uint8_t sn, sockopt_type sotype, void* arg)
601+
int8_t WIZCHIP_EXPORT(setsockopt)(uint8_t sn, sockopt_type sotype, void* arg)
602602
{
603603
// M20131220 : Remove warning
604604
//uint8_t tmp;
@@ -651,7 +651,7 @@ int8_t setsockopt(uint8_t sn, sockopt_type sotype, void* arg)
651651
return SOCK_OK;
652652
}
653653

654-
int8_t getsockopt(uint8_t sn, sockopt_type sotype, void* arg)
654+
int8_t WIZCHIP_EXPORT(getsockopt)(uint8_t sn, sockopt_type sotype, void* arg)
655655
{
656656
CHECK_SOCKNUM();
657657
switch(sotype)

drivers/wiznet5k/ethernet/socket.h

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,11 @@
7878
* Following figure shows network flow diagram by WIZnet SOCKET API.
7979
* @image html WIZnet_SOCKET.jpg "<WIZnet SOCKET API>"
8080
*/
81-
#ifndef _SOCKET_H_
82-
#define _SOCKET_H_
81+
#ifndef _WIZCHIP_SOCKET_H_
82+
#define _WIZCHIP_SOCKET_H_
83+
84+
// use this macro for exported names to avoid name clashes
85+
#define WIZCHIP_EXPORT(name) wizchip_ ## name
8386

8487
#include "wizchip_conf.h"
8588

@@ -147,7 +150,7 @@
147150
* @ref SOCKERR_SOCKMODE - Not support socket mode as TCP, UDP, and so on. \n
148151
* @ref SOCKERR_SOCKFLAG - Invaild socket flag.
149152
*/
150-
int8_t socket(uint8_t sn, uint8_t protocol, uint16_t port, uint8_t flag);
153+
int8_t WIZCHIP_EXPORT(socket)(uint8_t sn, uint8_t protocol, uint16_t port, uint8_t flag);
151154

152155
/**
153156
* @ingroup WIZnet_socket_APIs
@@ -159,7 +162,7 @@ int8_t socket(uint8_t sn, uint8_t protocol, uint16_t port, uint8_t flag);
159162
* @return @b Success : @ref SOCK_OK \n
160163
* @b Fail : @ref SOCKERR_SOCKNUM - Invalid socket number
161164
*/
162-
int8_t close(uint8_t sn);
165+
int8_t WIZCHIP_EXPORT(close)(uint8_t sn);
163166

164167
/**
165168
* @ingroup WIZnet_socket_APIs
@@ -172,7 +175,7 @@ int8_t close(uint8_t sn);
172175
* @b Fail :\n @ref SOCKERR_SOCKINIT - Socket is not initialized \n
173176
* @ref SOCKERR_SOCKCLOSED - Socket closed unexpectedly.
174177
*/
175-
int8_t listen(uint8_t sn);
178+
int8_t WIZCHIP_EXPORT(listen)(uint8_t sn);
176179

177180
/**
178181
* @ingroup WIZnet_socket_APIs
@@ -195,7 +198,7 @@ int8_t listen(uint8_t sn);
195198
* @ref SOCKERR_TIMEOUT - Timeout occurred during request connection\n
196199
* @ref SOCK_BUSY - In non-block io mode, it returned immediately\n
197200
*/
198-
int8_t connect(uint8_t sn, uint8_t * addr, uint16_t port);
201+
int8_t WIZCHIP_EXPORT(connect)(uint8_t sn, uint8_t * addr, uint16_t port);
199202

200203
/**
201204
* @ingroup WIZnet_socket_APIs
@@ -212,7 +215,7 @@ int8_t connect(uint8_t sn, uint8_t * addr, uint16_t port);
212215
* @ref SOCKERR_TIMEOUT - Timeout occurred \n
213216
* @ref SOCK_BUSY - Socket is busy.
214217
*/
215-
int8_t disconnect(uint8_t sn);
218+
int8_t WIZCHIP_EXPORT(disconnect)(uint8_t sn);
216219

217220
/**
218221
* @ingroup WIZnet_socket_APIs
@@ -232,7 +235,7 @@ int8_t disconnect(uint8_t sn);
232235
* @ref SOCKERR_DATALEN - zero data length \n
233236
* @ref SOCK_BUSY - Socket is busy.
234237
*/
235-
int32_t send(uint8_t sn, uint8_t * buf, uint16_t len);
238+
int32_t WIZCHIP_EXPORT(send)(uint8_t sn, uint8_t * buf, uint16_t len);
236239

237240
/**
238241
* @ingroup WIZnet_socket_APIs
@@ -254,7 +257,7 @@ int32_t send(uint8_t sn, uint8_t * buf, uint16_t len);
254257
* @ref SOCKERR_DATALEN - zero data length \n
255258
* @ref SOCK_BUSY - Socket is busy.
256259
*/
257-
int32_t recv(uint8_t sn, uint8_t * buf, uint16_t len);
260+
int32_t WIZCHIP_EXPORT(recv)(uint8_t sn, uint8_t * buf, uint16_t len);
258261

259262
/**
260263
* @ingroup WIZnet_socket_APIs
@@ -282,7 +285,7 @@ int32_t recv(uint8_t sn, uint8_t * buf, uint16_t len);
282285
* @ref SOCKERR_TIMEOUT - Timeout occurred \n
283286
* @ref SOCK_BUSY - Socket is busy.
284287
*/
285-
int32_t sendto(uint8_t sn, uint8_t * buf, uint16_t len, uint8_t * addr, uint16_t port);
288+
int32_t WIZCHIP_EXPORT(sendto)(uint8_t sn, uint8_t * buf, uint16_t len, uint8_t * addr, uint16_t port);
286289

287290
/**
288291
* @ingroup WIZnet_socket_APIs
@@ -312,7 +315,7 @@ int32_t sendto(uint8_t sn, uint8_t * buf, uint16_t len, uint8_t * addr, uint16_t
312315
* @ref SOCKERR_SOCKNUM - Invalid socket number \n
313316
* @ref SOCKBUSY - Socket is busy.
314317
*/
315-
int32_t recvfrom(uint8_t sn, uint8_t * buf, uint16_t len, uint8_t * addr, uint16_t *port);
318+
int32_t WIZCHIP_EXPORT(recvfrom)(uint8_t sn, uint8_t * buf, uint16_t len, uint8_t * addr, uint16_t *port);
316319

317320

318321
/////////////////////////////
@@ -399,7 +402,7 @@ typedef enum
399402
* @return @b Success @ref SOCK_OK \n
400403
* @b fail @ref SOCKERR_ARG - Invalid argument\n
401404
*/
402-
int8_t ctlsocket(uint8_t sn, ctlsock_type cstype, void* arg);
405+
int8_t WIZCHIP_EXPORT(ctlsocket)(uint8_t sn, ctlsock_type cstype, void* arg);
403406

404407
/**
405408
* @ingroup WIZnet_socket_APIs
@@ -427,7 +430,7 @@ int8_t ctlsocket(uint8_t sn, ctlsock_type cstype, void* arg);
427430
* - @ref SOCKERR_SOCKOPT - Invalid socket option or its value \n
428431
* - @ref SOCKERR_TIMEOUT - Timeout occurred when sending keep-alive packet \n
429432
*/
430-
int8_t setsockopt(uint8_t sn, sockopt_type sotype, void* arg);
433+
int8_t WIZCHIP_EXPORT(setsockopt)(uint8_t sn, sockopt_type sotype, void* arg);
431434

432435
/**
433436
* @ingroup WIZnet_socket_APIs
@@ -461,6 +464,6 @@ int8_t setsockopt(uint8_t sn, sockopt_type sotype, void* arg);
461464
* When SO_PACKINFO value is PACK_FIRST and the return value of recvfrom() is zero,
462465
* This means the zero byte UDP data(UDP Header only) received.
463466
*/
464-
int8_t getsockopt(uint8_t sn, sockopt_type sotype, void* arg);
467+
int8_t WIZCHIP_EXPORT(getsockopt)(uint8_t sn, sockopt_type sotype, void* arg);
465468

466-
#endif // _SOCKET_H_
469+
#endif // _WIZCHIP_SOCKET_H_

drivers/wiznet5k/internet/dns/dns.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -521,21 +521,21 @@ int8_t DNS_run(uint8_t * dns_ip, uint8_t * name, uint8_t * ip_from_dns)
521521
hal_sys_tick = HAL_GetTick();
522522

523523
// Socket open
524-
socket(DNS_SOCKET, Sn_MR_UDP, 0, 0);
524+
WIZCHIP_EXPORT(socket)(DNS_SOCKET, Sn_MR_UDP, 0, 0);
525525

526526
#ifdef _DNS_DEBUG_
527527
printf("> DNS Query to DNS Server : %d.%d.%d.%d\r\n", dns_ip[0], dns_ip[1], dns_ip[2], dns_ip[3]);
528528
#endif
529529

530530
len = dns_makequery(0, (char *)name, pDNSMSG, MAX_DNS_BUF_SIZE);
531-
sendto(DNS_SOCKET, pDNSMSG, len, dns_ip, IPPORT_DOMAIN);
531+
WIZCHIP_EXPORT(sendto)(DNS_SOCKET, pDNSMSG, len, dns_ip, IPPORT_DOMAIN);
532532

533533
while (1)
534534
{
535535
if ((len = getSn_RX_RSR(DNS_SOCKET)) > 0)
536536
{
537537
if (len > MAX_DNS_BUF_SIZE) len = MAX_DNS_BUF_SIZE;
538-
len = recvfrom(DNS_SOCKET, pDNSMSG, len, ip, &port);
538+
len = WIZCHIP_EXPORT(recvfrom)(DNS_SOCKET, pDNSMSG, len, ip, &port);
539539
#ifdef _DNS_DEBUG_
540540
printf("> Receive DNS message from %d.%d.%d.%d(%d). len = %d\r\n", ip[0], ip[1], ip[2], ip[3],port,len);
541541
#endif
@@ -556,10 +556,10 @@ int8_t DNS_run(uint8_t * dns_ip, uint8_t * name, uint8_t * ip_from_dns)
556556
#ifdef _DNS_DEBUG_
557557
printf("> DNS Timeout\r\n");
558558
#endif
559-
sendto(DNS_SOCKET, pDNSMSG, len, dns_ip, IPPORT_DOMAIN);
559+
WIZCHIP_EXPORT(sendto)(DNS_SOCKET, pDNSMSG, len, dns_ip, IPPORT_DOMAIN);
560560
}
561561
}
562-
close(DNS_SOCKET);
562+
WIZCHIP_EXPORT(close)(DNS_SOCKET);
563563
// Return value
564564
// 0 > : failed / 1 - success
565565
return ret;

0 commit comments

Comments
 (0)