1 /**************************************************************************** 2 * include/nuttx/net/net.h 3 * 4 * Licensed to the Apache Software Foundation (ASF) under one or more 5 * contributor license agreements. See the NOTICE file distributed with 6 * this work for additional information regarding copyright ownership. The 7 * ASF licenses this file to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance with the 9 * License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, software 14 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 15 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 16 * License for the specific language governing permissions and limitations 17 * under the License. 18 * 19 ****************************************************************************/ 20 21 #ifndef __INCLUDE_NUTTX_NET_NET_H 22 #define __INCLUDE_NUTTX_NET_NET_H 23 24 /**************************************************************************** 25 * Included Files 26 ****************************************************************************/ 27 28 #include "vfs_config.h" 29 #ifdef LOSCFG_NET_LWIP_SACK 30 31 #include <sys/socket.h> 32 #include <stdint.h> 33 34 #include <stdarg.h> 35 #include <semaphore.h> 36 #include "lwip/sockets.h" 37 38 /**************************************************************************** 39 * Pre-processor Definitions 40 ****************************************************************************/ 41 42 /* Most internal network OS interfaces are not available in the user space in 43 * PROTECTED and KERNEL builds. In that context, the corresponding 44 * application network interfaces must be used. The differences between the 45 * two sets of interfaces are: The internal OS interfaces (1) do not cause 46 * cancellation points and (2) they do not modify the errno variable. 47 * 48 * This is only important when compiling libraries (libc or libnx) that are 49 * used both by the OS (libkc.a and libknx.a) or by the applications 50 * (libuc.a and libunx.a). The that case, the correct interface must be 51 * used for the build context. 52 * 53 * REVISIT: In the flat build, the same functions must be used both by 54 * the OS and by applications. We have to use the normal user functions 55 * in this case or we will fail to set the errno or fail to create the 56 * cancellation point. 57 * 58 * The interfaces accept(), read(), recv(), recvfrom(), write(), send(), 59 * sendto() are all cancellation points. 60 * 61 * REVISIT: These cancellation points are an issue and may cause 62 * violations: It use of these internally will cause the calling function 63 * to become a cancellation points! 64 */ 65 66 #if !defined(CONFIG_BUILD_FLAT) && defined(__KERNEL__) 67 # define _NX_SEND(s,b,l,f) nx_send(s,b,l,f) 68 # define _NX_RECV(s,b,l,f) nx_recv(s,b,l,f) 69 # define _NX_RECVFROM(s,b,l,f,a,n) nx_recvfrom(s,b,l,f,a,n) 70 # define _NX_GETERRNO(r) (-(r)) 71 # define _NX_GETERRVAL(r) (r) 72 #else 73 # define _NX_SEND(s,b,l,f) send(s,b,l,f) 74 # define _NX_RECV(s,b,l,f) recv(s,b,l,f) 75 # define _NX_RECVFROM(s,b,l,f,a,n) recvfrom(s,b,l,f,a,n) 76 # define _NX_GETERRNO(r) errno 77 # define _NX_GETERRVAL(r) (-errno) 78 #endif 79 80 /* Socket descriptors are the index into the TCB sockets list, offset by the 81 * following amount. This offset is used to distinguish file descriptors from 82 * socket descriptors 83 */ 84 85 #define __SOCKFD_OFFSET CONFIG_NFILE_DESCRIPTORS 86 87 /* Capabilities of a socket */ 88 89 #define SOCKCAP_NONBLOCKING (1 << 0) /* Bit 0: Socket supports non-blocking 90 * operation. */ 91 92 /**************************************************************************** 93 * Public Types 94 ****************************************************************************/ 95 96 /* Link layer type. This type is used with netdev_register in order to 97 * identify the type of the network driver. 98 */ 99 100 enum net_lltype_e 101 { 102 NET_LL_ETHERNET = 0, /* Ethernet */ 103 NET_LL_SLIP, /* Serial Line Internet Protocol (SLIP) */ 104 NET_LL_PPP /* Point-to-Point Protocol (PPP) */ 105 }; 106 107 /* This defines a bitmap big enough for one bit for each socket option */ 108 109 typedef uint16_t sockopt_t; 110 111 /* This defines the storage size of a timeout value. This effects only 112 * range of supported timeout values. With an LSB in seciseconds, the 113 * 16-bit maximum of 65535 corresponds to 1 hr 49 min 13.5 sec at decisecond 114 * resolution. 115 */ 116 117 typedef uint16_t socktimeo_t; 118 119 /* This type defines the type of the socket capabilities set */ 120 121 typedef uint8_t sockcaps_t; 122 123 /* This callbacks are socket operations that may be performed on a socket of 124 * a given address family. 125 */ 126 127 struct file; /* Forward reference */ 128 struct socket; /* Forward reference */ 129 struct pollfd; /* Forward reference */ 130 131 struct sock_intf_s 132 { 133 CODE int (*si_setup)(FAR struct socket *psock, int protocol); 134 CODE sockcaps_t (*si_sockcaps)(FAR struct socket *psock); 135 CODE void (*si_addref)(FAR struct socket *psock); 136 CODE int (*si_bind)(FAR struct socket *psock, 137 FAR const struct sockaddr *addr, socklen_t addrlen); 138 CODE int (*si_getsockname)(FAR struct socket *psock, 139 FAR struct sockaddr *addr, FAR socklen_t *addrlen); 140 CODE int (*si_getpeername)(FAR struct socket *psock, 141 FAR struct sockaddr *addr, FAR socklen_t *addrlen); 142 CODE int (*si_listen)(FAR struct socket *psock, int backlog); 143 CODE int (*si_connect)(FAR struct socket *psock, 144 FAR const struct sockaddr *addr, socklen_t addrlen); 145 CODE int (*si_accept)(FAR struct socket *psock, 146 FAR struct sockaddr *addr, FAR socklen_t *addrlen, 147 FAR struct socket *newsock); 148 CODE int (*si_poll)(FAR struct socket *psock, 149 FAR struct pollfd *fds, bool setup); 150 CODE ssize_t (*si_send)(FAR struct socket *psock, FAR const void *buf, 151 size_t len, int flags); 152 CODE ssize_t (*si_sendto)(FAR struct socket *psock, FAR const void *buf, 153 size_t len, int flags, FAR const struct sockaddr *to, 154 socklen_t tolen); 155 #ifdef CONFIG_NET_SENDFILE 156 CODE ssize_t (*si_sendfile)(FAR struct socket *psock, 157 FAR struct file *infile, FAR off_t *offset, 158 size_t count); 159 #endif 160 CODE ssize_t (*si_recvfrom)(FAR struct socket *psock, FAR void *buf, 161 size_t len, int flags, FAR struct sockaddr *from, 162 FAR socklen_t *fromlen); 163 CODE int (*si_close)(FAR struct socket *psock); 164 #ifdef CONFIG_NET_USRSOCK 165 CODE int (*si_ioctl)(FAR struct socket *psock, int cmd, 166 FAR void *arg, size_t arglen); 167 #endif 168 }; 169 170 /* Each socket refers to a connection structure of type FAR void *. Each 171 * socket type will have a different connection structure type bound to its 172 * sockets. The fields at the the beginning of each connection type must 173 * begin the same content prologue as struct socket_conn_s and must be cast 174 * compatible with struct socket_conn_s. Connection-specific content may 175 * then follow the common prologue fields. 176 */ 177 178 struct devif_callback_s; /* Forward reference */ 179 180 /* This is the internal representation of a socket reference by a file 181 * descriptor. 182 */ 183 184 struct devif_callback_s; /* Forward reference */ 185 186 struct socket 187 { 188 int16_t s_crefs; /* Reference count on the socket */ 189 uint8_t s_domain; /* IP domain: PF_INET, PF_INET6, or PF_PACKET */ 190 uint8_t s_type; /* Protocol type: Only SOCK_STREAM or 191 * SOCK_DGRAM */ 192 uint8_t s_flags; /* See _SF_* definitions */ 193 194 /* Socket options */ 195 196 #ifdef CONFIG_NET_SOCKOPTS 197 sockopt_t s_options; /* Selected socket options */ 198 socktimeo_t s_rcvtimeo; /* Receive timeout value (in deciseconds) */ 199 socktimeo_t s_sndtimeo; /* Send timeout value (in deciseconds) */ 200 #ifdef CONFIG_NET_SOLINGER 201 socktimeo_t s_linger; /* Linger timeout value (in deciseconds) */ 202 #endif 203 #endif 204 205 void *s_conn; /* Connection inherits from struct socket_conn_s */ 206 207 /* Socket interface */ 208 209 FAR const struct sock_intf_s *s_sockif; 210 211 #if defined(CONFIG_NET_TCP_WRITE_BUFFERS) || \ 212 defined(CONFIG_NET_UDP_WRITE_BUFFERS) 213 /* Callback instance for TCP send() or UDP sendto() */ 214 215 struct devif_callback_s *s_sndcb; 216 #endif 217 }; 218 219 /* Callback from netdev_foreach() */ 220 221 struct net_driver_s; /* Forward reference. Defined in net/netdev.h */ 222 typedef int (*netdev_callback_t)(struct net_driver_s *dev, void *arg); 223 224 #ifdef CONFIG_NET_NOINTS 225 226 /* Semaphore based locking for non-interrupt based logic. 227 * 228 * net_lock_t -- Not used. Only for compatibility 229 */ 230 231 typedef uint8_t net_lock_t; /* Not really used */ 232 233 #else 234 235 /* Enable/disable locking for interrupt based logic: 236 * 237 * net_lock_t -- The processor specific representation of interrupt state. 238 */ 239 240 # define net_lock_t irqstate_t 241 #endif 242 243 /**************************************************************************** 244 * Public Data 245 ****************************************************************************/ 246 247 #ifdef __cplusplus 248 #if __cplusplus 249 extern "C" { 250 #endif /* __cplusplus */ 251 #endif /* __cplusplus */ 252 253 /**************************************************************************** 254 * Public Function Prototypes 255 ****************************************************************************/ 256 257 /**************************************************************************** 258 * Name: net_initialize 259 * 260 * Description: 261 * This is called from the OS initialization logic at power-up reset in 262 * order to configure networking data structures. This is called prior 263 * to platform-specific driver initialization so that the networking 264 * subsystem is prepared to deal with network driver initialization 265 * actions. 266 * 267 * Actions performed in this initialization phase assume that base OS 268 * facilities such as semaphores are available but this logic cannot 269 * depend upon OS resources such as interrupts or timers which are not 270 * yet available. 271 * 272 * Input Parameters: 273 * None 274 * 275 * Returned Value: 276 * None 277 * 278 ****************************************************************************/ 279 280 void net_initialize(void); 281 282 /**************************************************************************** 283 * Critical section management. 284 * 285 * Re-entrant mutex based locking of the network is supported: 286 * 287 * net_lock() - Locks the network via a re-entrant mutex. 288 * net_unlock() - Unlocks the network. 289 * net_lockedwait() - Like pthread_cond_wait() except releases the 290 * network momentarily to wait on another semaphore. 291 * net_ioballoc() - Like iob_alloc() except releases the network 292 * momentarily to wait for an IOB to become 293 * available. 294 * 295 ****************************************************************************/ 296 297 /**************************************************************************** 298 * Name: net_lock 299 * 300 * Description: 301 * Take the network lock 302 * 303 * Input Parameters: 304 * None 305 * 306 * Returned Value: 307 * Zero (OK) is returned on success; a negated errno value is returned on 308 * failured (probably -ECANCELED). 309 * 310 ****************************************************************************/ 311 312 int net_lock(void); 313 314 /**************************************************************************** 315 * Name: net_unlock 316 * 317 * Description: 318 * Release the network lock. 319 * 320 * Input Parameters: 321 * None 322 * 323 * Returned Value: 324 * None 325 * 326 ****************************************************************************/ 327 328 void net_unlock(void); 329 330 /**************************************************************************** 331 * Name: net_timedwait 332 * 333 * Description: 334 * Atomically wait for sem (or a timeout( while temporarily releasing 335 * the lock on the network. 336 * 337 * Caution should be utilized. Because the network lock is relinquished 338 * during the wait, there could changes in the network state that occur 339 * before the lock is recovered. Your design should account for this 340 * possibility. 341 * 342 * Input Parameters: 343 * sem - A reference to the semaphore to be taken. 344 * abstime - The absolute time to wait until a timeout is declared. 345 * 346 * Returned Value: 347 * Zero (OK) is returned on success; a negated errno value is returned on 348 * any failure. 349 * 350 ****************************************************************************/ 351 352 struct timespec; 353 int net_timedwait(sem_t *sem, FAR const struct timespec *abstime); 354 355 /**************************************************************************** 356 * Name: net_lockedwait 357 * 358 * Description: 359 * Atomically wait for sem while temporarily releasing the network lock. 360 * 361 * Caution should be utilized. Because the network lock is relinquished 362 * during the wait, there could changes in the network state that occur 363 * before the lock is recovered. Your design should account for this 364 * possibility. 365 * 366 * Input Parameters: 367 * sem - A reference to the semaphore to be taken. 368 * 369 * Returned Value: 370 * Zero (OK) is returned on success; a negated errno value is returned on 371 * any failure. 372 * 373 ****************************************************************************/ 374 375 int net_lockedwait(sem_t *sem); 376 377 /**************************************************************************** 378 * Name: net_ioballoc 379 * 380 * Description: 381 * Allocate an IOB. If no IOBs are available, then atomically wait for 382 * for the IOB while temporarily releasing the lock on the network. 383 * 384 * Caution should be utilized. Because the network lock is relinquished 385 * during the wait, there could changes in the network state that occur 386 * before the lock is recovered. Your design should account for this 387 * possibility. 388 * 389 * Input Parameters: 390 * throttled - An indication of the IOB allocation is "throttled" 391 * 392 * Returned Value: 393 * A pointer to the newly allocated IOB is returned on success. NULL is 394 * returned on any allocation failure. 395 * 396 ****************************************************************************/ 397 398 #ifdef CONFIG_MM_IOB 399 FAR struct iob_s *net_ioballoc(bool throttled, enum iob_user_e consumerid); 400 #endif 401 402 /**************************************************************************** 403 * Name: net_setipid 404 * 405 * Description: 406 * This function may be used at boot time to set the initial ip_id. 407 * 408 * Assumptions: 409 * 410 ****************************************************************************/ 411 412 void net_setipid(uint16_t id); 413 414 /**************************************************************************** 415 * Name: net_checksd 416 * 417 * Description: 418 * Check if the socket descriptor is valid for the provided TCB and if it 419 * supports the requested access. This trivial operation is part of the 420 * fdopen() operation when the fdopen() is performed on a socket descriptor. 421 * It simply performs some sanity checking before permitting the socket 422 * descriptor to be wrapped as a C FILE stream. 423 * 424 ****************************************************************************/ 425 426 int net_checksd(int fd, int oflags); 427 428 429 430 431 /**************************************************************************** 432 * Name: sockfd_socket 433 * 434 * Description: 435 * Given a socket descriptor, return the underlying socket structure. 436 * 437 * Input Parameters: 438 * sockfd - The socket descriptor index o use. 439 * 440 * Returned Value: 441 * On success, a reference to the socket structure associated with the 442 * the socket descriptor is returned. NULL is returned on any failure. 443 * 444 ****************************************************************************/ 445 446 struct socket *sockfd_socket(int sockfd); 447 448 /**************************************************************************** 449 * Name: psock_socket 450 * 451 * Description: 452 * socket() creates an endpoint for communication and returns a socket 453 * structure. 454 * 455 * Input Parameters: 456 * domain (see sys/socket.h) 457 * type (see sys/socket.h) 458 * protocol (see sys/socket.h) 459 * psock A pointer to a user allocated socket structure to be 460 * initialized. 461 * 462 * Returned Value: 463 * Returns zero (OK) on success. On failure, it returns a negated errno 464 * value to indicate the nature of the error: 465 * 466 * EACCES 467 * Permission to create a socket of the specified type and/or protocol 468 * is denied. 469 * EAFNOSUPPORT 470 * The implementation does not support the specified address family. 471 * EINVAL 472 * Unknown protocol, or protocol family not available. 473 * EMFILE 474 * Process file table overflow. 475 * ENFILE 476 * The system limit on the total number of open files has been reached. 477 * ENOBUFS or ENOMEM 478 * Insufficient memory is available. The socket cannot be created until 479 * sufficient resources are freed. 480 * EPROTONOSUPPORT 481 * The protocol type or the specified protocol is not supported within 482 * this domain. 483 * 484 * Assumptions: 485 * 486 ****************************************************************************/ 487 488 int psock_socket(int domain, int type, int protocol, 489 struct socket *psock); 490 491 /**************************************************************************** 492 * Name: net_close 493 * 494 * Description: 495 * Performs the close operation on socket descriptors 496 * 497 * Input Parameters: 498 * sockfd Socket descriptor of socket 499 * 500 * Returned Value: 501 * Returns zero (OK) on success. On failure, it returns a negated errno 502 * value to indicate the nature of the error. 503 * 504 * Assumptions: 505 * 506 ****************************************************************************/ 507 508 int net_close(int sockfd); 509 510 /**************************************************************************** 511 * Name: psock_close 512 * 513 * Description: 514 * Performs the close operation on a socket instance 515 * 516 * Input Parameters: 517 * psock Socket instance 518 * 519 * Returned Value: 520 * Returns zero (OK) on success. On failure, it returns a negated errno 521 * value to indicate the nature of the error. 522 * 523 ****************************************************************************/ 524 525 int psock_close(struct socket *psock); 526 527 /**************************************************************************** 528 * Name: psock_bind 529 * 530 * Description: 531 * bind() gives the socket 'psock' the local address 'addr'. 'addr' is 532 * 'addrlen' bytes long. Traditionally, this is called "assigning a name to 533 * a socket." When a socket is created with socket, it exists in a name 534 * space (address family) but has no name assigned. 535 * 536 * Input Parameters: 537 * psock Socket structure of the socket to bind 538 * addr Socket local address 539 * addrlen Length of 'addr' 540 * 541 * Returned Value: 542 * Returns zero (OK) on success. On failure, it returns a negated errno 543 * value to indicate the nature of the error. 544 * 545 * EACCES 546 * The address is protected, and the user is not the superuser. 547 * EADDRINUSE 548 * The given address is already in use. 549 * EINVAL 550 * The socket is already bound to an address. 551 * ENOTSOCK 552 * psock is a descriptor for a file, not a socket. 553 * 554 * Assumptions: 555 * 556 ****************************************************************************/ 557 558 struct sockaddr; /* Forward reference. See nuttx/include/sys/socket.h */ 559 int psock_bind(struct socket *psock, const struct sockaddr *addr, 560 socklen_t addrlen); 561 562 /**************************************************************************** 563 * Name: psock_listen 564 * 565 * Description: 566 * To accept connections, a socket is first created with psock_socket(), a 567 * willingness to accept incoming connections and a queue limit for 568 * incoming connections are specified with psock_listen(), and then the 569 * connections are accepted with psock_accept(). The psock_listen() call 570 * applies only to sockets of type SOCK_STREAM or SOCK_SEQPACKET. 571 * 572 * Input Parameters: 573 * psock Reference to an internal, boound socket structure. 574 * backlog The maximum length the queue of pending connections may grow. 575 * If a connection request arrives with the queue full, the client 576 * may receive an error with an indication of ECONNREFUSED or, 577 * if the underlying protocol supports retransmission, the request 578 * may be ignored so that retries succeed. 579 * 580 * Returned Value: 581 * Returns zero (OK) on success. On failure, it returns a negated errno 582 * value to indicate the nature of the error. 583 * 584 * EADDRINUSE 585 * Another socket is already listening on the same port. 586 * EOPNOTSUPP 587 * The socket is not of a type that supports the listen operation. 588 * 589 ****************************************************************************/ 590 591 int psock_listen(FAR struct socket *psock, int backlog); 592 593 /**************************************************************************** 594 * Name: psock_accept 595 * 596 * Description: 597 * The psock_accept function is used with connection-based socket types 598 * (SOCK_STREAM, SOCK_SEQPACKET and SOCK_RDM). It extracts the first 599 * connection request on the queue of pending connections, creates a new 600 * connected socket with mostly the same properties as 'sockfd', and 601 * allocates a new socket descriptor for the socket, which is returned. The 602 * newly created socket is no longer in the listening state. The original 603 * socket 'sockfd' is unaffected by this call. Per file descriptor flags 604 * are not inherited across an psock_accept. 605 * 606 * The 'sockfd' argument is a socket descriptor that has been created with 607 * socket(), bound to a local address with bind(), and is listening for 608 * connections after a call to listen(). 609 * 610 * On return, the 'addr' structure is filled in with the address of the 611 * connecting entity. The 'addrlen' argument initially contains the size 612 * of the structure pointed to by 'addr'; on return it will contain the 613 * actual length of the address returned. 614 * 615 * If no pending connections are present on the queue, and the socket is 616 * not marked as non-blocking, psock_accept blocks the caller until a 617 * connection is present. If the socket is marked non-blocking and no 618 * pending connections are present on the queue, psock_accept returns 619 * EAGAIN. 620 * 621 * Input Parameters: 622 * psock Reference to the listening socket structure 623 * addr Receives the address of the connecting client 624 * addrlen Input: allocated size of 'addr', Return: returned size of 'addr' 625 * newsock Location to return the accepted socket information. 626 * 627 * Returned Value: 628 * Returns zero (OK) on success. On failure, it returns a negated errno 629 * value to indicate the nature of the error. 630 * 631 * EAGAIN or EWOULDBLOCK 632 * The socket is marked non-blocking and no connections are present to 633 * be accepted. 634 * EOPNOTSUPP 635 * The referenced socket is not of type SOCK_STREAM. 636 * EINTR 637 * The system call was interrupted by a signal that was caught before 638 * a valid connection arrived. 639 * ECONNABORTED 640 * A connection has been aborted. 641 * EINVAL 642 * Socket is not listening for connections. 643 * EMFILE 644 * The per-process limit of open file descriptors has been reached. 645 * ENFILE 646 * The system maximum for file descriptors has been reached. 647 * EFAULT 648 * The addr parameter is not in a writable part of the user address 649 * space. 650 * ENOBUFS or ENOMEM 651 * Not enough free memory. 652 * EPROTO 653 * Protocol error. 654 * EPERM 655 * Firewall rules forbid connection. 656 * 657 ****************************************************************************/ 658 659 int psock_accept(FAR struct socket *psock, FAR struct sockaddr *addr, 660 FAR socklen_t *addrlen, FAR struct socket *newsock); 661 662 /**************************************************************************** 663 * Name: psock_connect 664 * 665 * Description: 666 * connect() connects the socket referred to by the structure 'psock' 667 * to the address specified by 'addr'. The addrlen argument specifies 668 * the size of 'addr'. The format of the address in 'addr' is 669 * determined by the address space of the socket 'psock'. 670 * 671 * If the socket 'psock' is of type SOCK_DGRAM then 'addr' is the address 672 * to which datagrams are sent by default, and the only address from which 673 * datagrams are received. If the socket is of type SOCK_STREAM or 674 * SOCK_SEQPACKET, this call attempts to make a connection to the socket 675 * that is bound to the address specified by 'addr'. 676 * 677 * Generally, connection-based protocol sockets may successfully connect() 678 * only once; connectionless protocol sockets may use connect() multiple 679 * times to change their association. Connectionless sockets may dissolve 680 * the association by connecting to an address with the sa_family member of 681 * sockaddr set to AF_UNSPEC. 682 * 683 * Input Parameters: 684 * psock Pointer to a socket structure initialized by psock_socket() 685 * addr Server address (form depends on type of socket) 686 * addrlen Length of actual 'addr' 687 * 688 * Returned Value: 689 * Returns zero (OK) on success. On failure, it returns a negated errno 690 * value to indicate the nature of the error. 691 * 692 * EACCES, EPERM 693 * The user tried to connect to a broadcast address without having the 694 * socket broadcast flag enabled or the connection request failed 695 * because of a local firewall rule. 696 * EADDRINUSE 697 * Local address is already in use. 698 * EAFNOSUPPORT 699 * The passed address didn't have the correct address family in its 700 * sa_family field. 701 * EAGAIN 702 * No more free local ports or insufficient entries in the routing 703 * cache. 704 * EALREADY 705 * The socket is non-blocking and a previous connection attempt has 706 * not yet been completed. 707 * EBADF 708 * The file descriptor is not a valid index in the descriptor table. 709 * ECONNREFUSED 710 * No one listening on the remote address. 711 * EFAULT 712 * The socket structure address is outside the user's address space. 713 * EINPROGRESS 714 * The socket is non-blocking and the connection cannot be completed 715 * immediately. 716 * EINTR 717 * The system call was interrupted by a signal that was caught. 718 * EISCONN 719 * The socket is already connected. 720 * ENETUNREACH 721 * Network is unreachable. 722 * ENOTSOCK 723 * The file descriptor is not associated with a socket. 724 * ETIMEDOUT 725 * Timeout while attempting connection. The server may be too busy 726 * to accept new connections. 727 * 728 * Assumptions: 729 * 730 ****************************************************************************/ 731 732 int psock_connect(struct socket *psock, const struct sockaddr *addr, 733 socklen_t addrlen); 734 735 /**************************************************************************** 736 * Name: psock_send 737 * 738 * Description: 739 * The psock_send() call may be used only when the socket is in a 740 * connected state (so that the intended recipient is known). This is an 741 * internal OS interface. It is functionally equivalent to send() except 742 * that: 743 * 744 * - It is not a cancellation point, 745 * - It does not modify the errno variable, and 746 * - I accepts the internal socket structure as an input rather than an 747 * task-specific socket descriptor. 748 * 749 * See comments with send() for more a more complete description of the 750 * functionality. 751 * 752 * Input Parameters: 753 * psock - An instance of the internal socket structure. 754 * buf - Data to send 755 * len - Length of data to send 756 * flags - Send flags 757 * 758 * Returned Value: 759 * On success, returns the number of characters sent. On any failure, a 760 * negated errno value is returned (See comments with send() for a list 761 * of the appropriate errno value). 762 * 763 ****************************************************************************/ 764 765 ssize_t psock_send(FAR struct socket *psock, const void *buf, size_t len, 766 int flags); 767 768 /**************************************************************************** 769 * Name: nx_send 770 * 771 * Description: 772 * The nx_send() call may be used only when the socket is in a 773 * connected state (so that the intended recipient is known). This is an 774 * internal OS interface. It is functionally equivalent to send() except 775 * that: 776 * 777 * - It is not a cancellation point, and 778 * - It does not modify the errno variable. 779 * 780 * See comments with send() for more a more complete description of the 781 * functionality. 782 * 783 * Input Parameters: 784 * sockfd - Socket descriptor of the socket 785 * buf - Data to send 786 * len - Length of data to send 787 * flags - Send flags 788 * 789 * Returned Value: 790 * On success, returns the number of characters sent. On any failure, a 791 * negated errno value is returned (See comments with send() for a list 792 * of the appropriate errno value). 793 * 794 ****************************************************************************/ 795 796 ssize_t nx_send(int sockfd, FAR const void *buf, size_t len, int flags); 797 798 /**************************************************************************** 799 * Name: psock_sendto 800 * 801 * Description: 802 * If sendto() is used on a connection-mode (SOCK_STREAM, SOCK_SEQPACKET) 803 * socket, the parameters to and 'tolen' are ignored (and the error EISCONN 804 * may be returned when they are not NULL and 0), and the error ENOTCONN is 805 * returned when the socket was not actually connected. 806 * 807 * Input Parameters: 808 * psock A pointer to a NuttX-specific, internal socket structure 809 * buf Data to send 810 * len Length of data to send 811 * flags Send flags 812 * to Address of recipient 813 * tolen The length of the address structure 814 * 815 * Returned Value: 816 * On success, returns the number of characters sent. On any failure, a 817 * negated errno value is returned. One of: 818 * 819 * EAGAIN or EWOULDBLOCK 820 * The socket is marked non-blocking and the requested operation 821 * would block. 822 * EBADF 823 * An invalid descriptor was specified. 824 * ECONNRESET 825 * Connection reset by peer. 826 * EDESTADDRREQ 827 * The socket is not connection-mode, and no peer address is set. 828 * EFAULT 829 * An invalid user space address was specified for a parameter. 830 * EINTR 831 * A signal occurred before any data was transmitted. 832 * EINVAL 833 * Invalid argument passed. 834 * EISCONN 835 * The connection-mode socket was connected already but a recipient 836 * was specified. (Now either this error is returned, or the recipient 837 * specification is ignored.) 838 * EMSGSIZE 839 * The socket type requires that message be sent atomically, and the 840 * size of the message to be sent made this impossible. 841 * ENOBUFS 842 * The output queue for a network interface was full. This generally 843 * indicates that the interface has stopped sending, but may be 844 * caused by transient congestion. 845 * ENOMEM 846 * No memory available. 847 * ENOTCONN 848 * The socket is not connected, and no target has been given. 849 * ENOTSOCK 850 * The argument s is not a socket. 851 * EOPNOTSUPP 852 * Some bit in the flags argument is inappropriate for the socket 853 * type. 854 * EPIPE 855 * The local end has been shut down on a connection oriented socket. 856 * In this case the process will also receive a SIGPIPE unless 857 * MSG_NOSIGNAL is set. 858 * 859 ****************************************************************************/ 860 861 ssize_t psock_sendto(struct socket *psock, const void *buf, 862 size_t len, int flags, const struct sockaddr *to, 863 socklen_t tolen); 864 865 /**************************************************************************** 866 * Name: psock_recvfrom 867 * 868 * Description: 869 * psock_recvfrom() receives messages from a socket, and may be used to 870 * receive data on a socket whether or not it is connection-oriented. 871 * This is an internal OS interface. It is functionally equivalent to 872 * recvfrom() except that: 873 * 874 * - It is not a cancellation point, 875 * - It does not modify the errno variable, and 876 * - I accepts the internal socket structure as an input rather than an 877 * task-specific socket descriptor. 878 * 879 * Input Parameters: 880 * psock - A pointer to a NuttX-specific, internal socket structure 881 * buf - Buffer to receive data 882 * len - Length of buffer 883 * flags - Receive flags 884 * from - Address of source (may be NULL) 885 * fromlen - The length of the address structure 886 * 887 * Returned Value: 888 * On success, returns the number of characters sent. If no data is 889 * available to be received and the peer has performed an orderly shutdown, 890 * recv() will return 0. Otherwise, on any failure, a negated errno value 891 * is returned (see comments with send() for a list of appropriate errno 892 * values). 893 * 894 ****************************************************************************/ 895 896 ssize_t psock_recvfrom(struct socket *psock, void *buf, size_t len, 897 int flags, struct sockaddr *from, 898 socklen_t *fromlen); 899 900 /* recv using the underlying socket structure */ 901 902 #define psock_recv(psock,buf,len,flags) \ 903 psock_recvfrom(psock,buf,len,flags,NULL,0) 904 905 /**************************************************************************** 906 * Name: nx_recvfrom 907 * 908 * Description: 909 * nx_recvfrom() receives messages from a socket, and may be used to 910 * receive data on a socket whether or not it is connection-oriented. 911 * This is an internal OS interface. It is functionally equivalent to 912 * recvfrom() except that: 913 * 914 * - It is not a cancellation point, and 915 * - It does not modify the errno variable. 916 * 917 * Input Parameters: 918 * sockfd - Socket descriptor of socket 919 * buf - Buffer to receive data 920 * len - Length of buffer 921 * flags - Receive flags 922 * from - Address of source (may be NULL) 923 * fromlen - The length of the address structure 924 * 925 * Returned Value: 926 * On success, returns the number of characters sent. If no data is 927 * available to be received and the peer has performed an orderly shutdown, 928 * recv() will return 0. Otherwise, on any failure, a negated errno value 929 * is returned (see comments with send() for a list of appropriate errno 930 * values). 931 * 932 ****************************************************************************/ 933 934 ssize_t nx_recvfrom(int sockfd, FAR void *buf, size_t len, int flags, 935 FAR struct sockaddr *from, FAR socklen_t *fromlen); 936 937 /* Internal version os recv */ 938 939 #define nx_recv(psock,buf,len,flags) nx_recvfrom(psock,buf,len,flags,NULL,0) 940 941 /**************************************************************************** 942 * Name: psock_getsockopt 943 * 944 * Description: 945 * getsockopt() retrieve thse value for the option specified by the 946 * 'option' argument for the socket specified by the 'psock' argument. If 947 * the size of the option value is greater than 'value_len', the value 948 * stored in the object pointed to by the 'value' argument will be silently 949 * truncated. Otherwise, the length pointed to by the 'value_len' argument 950 * will be modified to indicate the actual length of the'value'. 951 * 952 * The 'level' argument specifies the protocol level of the option. To 953 * retrieve options at the socket level, specify the level argument as 954 * SOL_SOCKET. 955 * 956 * See <sys/socket.h> a complete list of values for the 'option' argument. 957 * 958 * Input Parameters: 959 * psock Socket structure of the socket to query 960 * level Protocol level to set the option 961 * option identifies the option to get 962 * value Points to the argument value 963 * value_len The length of the argument value 964 * 965 * Returned Value: 966 * Returns zero (OK) on success. On failure, it returns a negated errno 967 * value to indicate the nature of the error: 968 * 969 * EINVAL 970 * The specified option is invalid at the specified socket 'level' or the 971 * socket has been shutdown. 972 * ENOPROTOOPT 973 * The 'option' is not supported by the protocol. 974 * ENOTSOCK 975 * The 'psock' argument does not refer to a socket. 976 * ENOBUFS 977 * Insufficient resources are available in the system to complete the 978 * call. 979 * 980 ****************************************************************************/ 981 982 int psock_getsockopt(struct socket *psock, int level, int option, 983 void *value, socklen_t *value_len); 984 985 /**************************************************************************** 986 * Name: psock_setsockopt 987 * 988 * Description: 989 * psock_setsockopt() sets the option specified by the 'option' argument, 990 * at the protocol level specified by the 'level' argument, to the value 991 * pointed to by the 'value' argument for the socket on the 'psock' 992 * argument. 993 * 994 * The 'level' argument specifies the protocol level of the option. To set 995 * options at the socket level, specify the level argument as SOL_SOCKET. 996 * 997 * See <sys/socket.h> a complete list of values for the 'option' argument. 998 * 999 * Input Parameters: 1000 * psock Socket structure of socket to operate on 1001 * level Protocol level to set the option 1002 * option identifies the option to set 1003 * value Points to the argument value 1004 * value_len The length of the argument value 1005 * 1006 * Returned Value: 1007 * Returns zero (OK) on success. On failure, it returns a negated errno 1008 * value to indicate the nature of the error: 1009 * 1010 * EDOM 1011 * The send and receive timeout values are too big to fit into the 1012 * timeout fields in the socket structure. 1013 * EINVAL 1014 * The specified option is invalid at the specified socket 'level' or the 1015 * socket has been shut down. 1016 * EISCONN 1017 * The socket is already connected, and a specified option cannot be set 1018 * while the socket is connected. 1019 * ENOPROTOOPT 1020 * The 'option' is not supported by the protocol. 1021 * ENOTSOCK 1022 * The 'sockfd' argument does not refer to a socket. 1023 * ENOMEM 1024 * There was insufficient memory available for the operation to complete. 1025 * ENOBUFS 1026 * Insufficient resources are available in the system to complete the 1027 * call. 1028 * 1029 * Assumptions: 1030 * 1031 ****************************************************************************/ 1032 1033 int psock_setsockopt(struct socket *psock, int level, int option, 1034 const void *value, socklen_t value_len); 1035 1036 /**************************************************************************** 1037 * Name: psock_getsockname 1038 * 1039 * Description: 1040 * The psock_getsockname() function retrieves the locally-bound name of the 1041 * the specified socket, stores this address in the sockaddr structure 1042 * pointed to by the 'addr' argument, and stores the length of this 1043 * address in the object pointed to by the 'addrlen' argument. 1044 * 1045 * If the actual length of the address is greater than the length of the 1046 * supplied sockaddr structure, the stored address will be truncated. 1047 * 1048 * If the socket has not been bound to a local name, the value stored in 1049 * the object pointed to by address is unspecified. 1050 * 1051 * Parameters: 1052 * psock Socket structure of socket to operate on 1053 * addr sockaddr structure to receive data [out] 1054 * addrlen Length of sockaddr structure [in/out] 1055 * 1056 * Returned Value: 1057 * On success, 0 is returned, the 'addr' argument points to the address 1058 * of the socket, and the 'addrlen' argument points to the length of the 1059 * address. Otherwise, -1 is returned and errno is set to indicate the 1060 * error. Possible errno values that may be returned include: 1061 * 1062 * EBADF - The socket argument is not a valid file descriptor. 1063 * ENOTSOCK - The socket argument does not refer to a socket. 1064 * EOPNOTSUPP - The operation is not supported for this socket's protocol. 1065 * ENOTCONN - The socket is not connected or otherwise has not had the 1066 * peer pre-specified. 1067 * EINVAL - The socket has been shut down. 1068 * ENOBUFS - Insufficient resources were available in the system to 1069 * complete the function. 1070 * 1071 ****************************************************************************/ 1072 1073 int psock_getsockname(FAR struct socket *psock, FAR struct sockaddr *addr, 1074 FAR socklen_t *addrlen); 1075 1076 /**************************************************************************** 1077 * Name: psock_getpeername 1078 * 1079 * Description: 1080 * The psock_getpeername() function retrieves the remote-connected name of 1081 * the specified socket, stores this address in the sockaddr structure 1082 * pointed to by the 'addr' argument, and stores the length of this address 1083 * in the object pointed to by the 'addrlen' argument. 1084 * 1085 * If the actual length of the address is greater than the length of the 1086 * supplied sockaddr structure, the stored address will be truncated. 1087 * 1088 * If the socket has not been bound to a local name, the value stored in 1089 * the object pointed to by address is unspecified. 1090 * 1091 * Parameters: 1092 * psock Socket structure of socket to operate on 1093 * addr sockaddr structure to receive data [out] 1094 * addrlen Length of sockaddr structure [in/out] 1095 * 1096 * Returned Value: 1097 * On success, 0 is returned, the 'addr' argument points to the address 1098 * of the socket, and the 'addrlen' argument points to the length of the 1099 * address. Otherwise, -1 is returned and errno is set to indicate the 1100 * error. Possible errno values that may be returned include: 1101 * 1102 * EBADF - The socket argument is not a valid file descriptor. 1103 * ENOTSOCK - The socket argument does not refer to a socket. 1104 * EOPNOTSUPP - The operation is not supported for this socket's protocol. 1105 * ENOTCONN - The socket is not connected or otherwise has not had the 1106 * peer pre-specified. 1107 * EINVAL - The socket has been shut down. 1108 * ENOBUFS - Insufficient resources were available in the system to 1109 * complete the function. 1110 * 1111 ****************************************************************************/ 1112 1113 int psock_getpeername(FAR struct socket *psock, FAR struct sockaddr *addr, 1114 FAR socklen_t *addrlen); 1115 1116 /**************************************************************************** 1117 * Name: psock_ioctl 1118 * 1119 * Description: 1120 * Perform network device specific operations. 1121 * 1122 * Input Parameters: 1123 * psock A pointer to a NuttX-specific, internal socket structure 1124 * cmd The ioctl command 1125 * arg The argument of the ioctl cmd 1126 * 1127 * Returned Value: 1128 * A non-negative value is returned on success; a negated errno value is 1129 * returned on any failure to indicate the nature of the failure: 1130 * 1131 * EBADF 1132 * 'psock' is not a valid, connected socket structure. 1133 * EFAULT 1134 * 'arg' references an inaccessible memory area. 1135 * ENOTTY 1136 * 'cmd' not valid. 1137 * EINVAL 1138 * 'arg' is not valid. 1139 * ENOTTY 1140 * 'sockfd' is not associated with a network device. 1141 * ENOTTY 1142 * The specified request does not apply to the kind of object that the 1143 * descriptor 'sockfd' references. 1144 * 1145 ****************************************************************************/ 1146 1147 int psock_ioctl(FAR struct socket *psock, int cmd, unsigned long arg); 1148 1149 /**************************************************************************** 1150 * Name: netdev_ioctl 1151 * 1152 * Description: 1153 * Perform network device specific operations. 1154 * 1155 * Input Parameters: 1156 * sockfd Socket descriptor of device 1157 * cmd The ioctl command 1158 * arg The argument of the ioctl cmd 1159 * 1160 * Returned Value: 1161 * A non-negative value is returned on success; a negated errno value is 1162 * returned on any failure to indicate the nature of the failure: 1163 * 1164 * EBADF 1165 * 'sockfd' is not a valid socket descriptor. 1166 * EFAULT 1167 * 'arg' references an inaccessible memory area. 1168 * ENOTTY 1169 * 'cmd' not valid. 1170 * EINVAL 1171 * 'arg' is not valid. 1172 * ENOTTY 1173 * 'sockfd' is not associated with a network device. 1174 * ENOTTY 1175 * The specified request does not apply to the kind of object that the 1176 * descriptor 'sockfd' references. 1177 * 1178 ****************************************************************************/ 1179 1180 int netdev_ioctl(int sockfd, int cmd, unsigned long arg); 1181 1182 /**************************************************************************** 1183 * Name: psock_poll 1184 * 1185 * Description: 1186 * The standard poll() operation redirects operations on socket descriptors 1187 * to this function. 1188 * 1189 * Input Parameters: 1190 * psock - An instance of the internal socket structure. 1191 * fds - The structure describing the events to be monitored, OR NULL if 1192 * this is a request to stop monitoring events. 1193 * setup - true: Setup up the poll; false: Teardown the poll 1194 * 1195 * Returned Value: 1196 * 0: Success; Negated errno on failure 1197 * 1198 ****************************************************************************/ 1199 1200 struct pollfd; /* Forward reference -- see poll.h */ 1201 1202 int psock_poll(struct socket *psock, struct pollfd *fds, bool setup); 1203 1204 /**************************************************************************** 1205 * Name: net_poll 1206 * 1207 * Description: 1208 * The standard poll() operation redirects operations on socket descriptors 1209 * to this function. 1210 * 1211 * Input Parameters: 1212 * fd - The socket descriptor of interest 1213 * fds - The structure describing the events to be monitored, OR NULL if 1214 * this is a request to stop monitoring events. 1215 * setup - true: Setup up the poll; false: Teardown the poll 1216 * 1217 * Returned Value: 1218 * 0: Success; Negated errno on failure 1219 * 1220 ****************************************************************************/ 1221 1222 struct pollfd; /* Forward reference -- see poll.h */ 1223 1224 int net_poll(int sockfd, struct pollfd *fds, bool setup); 1225 1226 /**************************************************************************** 1227 * Name: psock_dupsd 1228 * 1229 * Description: 1230 * Clone a socket descriptor to an arbitray descriptor number. If file 1231 * descriptors are implemented, then this is called by dup() for the case 1232 * of socket file descriptors. If file descriptors are not implemented, 1233 * then this function IS dup(). 1234 * 1235 * Returned Value: 1236 * On success, returns the number of characters sent. On any error, 1237 * a negated errno value is returned:. 1238 * 1239 ****************************************************************************/ 1240 1241 int psock_dupsd(FAR struct socket *psock, int minsd); 1242 1243 /**************************************************************************** 1244 * Name: net_dupsd 1245 * 1246 * Description: 1247 * Clone a socket descriptor to an arbitray descriptor number. If file 1248 * descriptors are implemented, then this is called by dup() for the case 1249 * of socket file descriptors. If file descriptors are not implemented, 1250 * then this function IS dup(). 1251 * 1252 * Returned Value: 1253 * On success, returns the number of characters sent. On any error, 1254 * a negated errno value is returned:. 1255 * 1256 ****************************************************************************/ 1257 1258 int net_dupsd(int sockfd, int minsd); 1259 1260 /**************************************************************************** 1261 * Name: net_dupsd2 1262 * 1263 * Description: 1264 * Clone a socket descriptor to an arbitray descriptor number. If file 1265 * descriptors are implemented, then this is called by dup2() for the case 1266 * of socket file descriptors. If file descriptors are not implemented, 1267 * then this function IS dup2(). 1268 * 1269 * Returned Value: 1270 * On success, returns the number of characters sent. On any error, 1271 * a negated errno value is returned:. 1272 * 1273 ****************************************************************************/ 1274 1275 int net_dupsd2(int sockfd1, int sockfd2); 1276 1277 /**************************************************************************** 1278 * Name: net_fstat 1279 * 1280 * Description: 1281 * Performs fstat operations on socket 1282 * 1283 * Input Parameters: 1284 * sockfd - Socket descriptor of the socket to operate on 1285 * bug - Caller-provided location in which to return the fstat data 1286 * 1287 * Returned Value: 1288 * Zero (OK) is returned on success; a negated errno value is returned on 1289 * any failure to indicate the nature of the failure. 1290 * 1291 ****************************************************************************/ 1292 1293 struct stat; /* Forward reference. See sys/stat.h */ 1294 1295 int net_fstat(int sockfd, FAR struct stat *buf); 1296 1297 /**************************************************************************** 1298 * Name: net_clone 1299 * 1300 * Description: 1301 * Performs the low level, common portion of net_dupsd() and net_dupsd2() 1302 * 1303 ****************************************************************************/ 1304 1305 int net_clone(struct socket *psock1, struct socket *psock2); 1306 1307 /**************************************************************************** 1308 * Name: net_sendfile 1309 * 1310 * Description: 1311 * The send() call may be used only when the socket is in a connected state 1312 * (so that the intended recipient is known). The only difference between 1313 * send() and write() is the presence of flags. With zero flags parameter, 1314 * send() is equivalent to write(). Also, send(sockfd,buf,len,flags) is 1315 * equivalent to sendto(sockfd,buf,len,flags,NULL,0). 1316 * 1317 * Input Parameters: 1318 * psock An instance of the internal socket structure. 1319 * buf Data to send 1320 * len Length of data to send 1321 * flags Send flags 1322 * 1323 * Returned Value: 1324 * On success, returns the number of characters sent. On error, 1325 * -1 is returned, and errno is set appropriately: 1326 * 1327 * EAGAIN or EWOULDBLOCK 1328 * The socket is marked non-blocking and the requested operation 1329 * would block. 1330 * EBADF 1331 * An invalid descriptor was specified. 1332 * ECONNRESET 1333 * Connection reset by peer. 1334 * EDESTADDRREQ 1335 * The socket is not connection-mode, and no peer address is set. 1336 * EFAULT 1337 * An invalid user space address was specified for a parameter. 1338 * EINTR 1339 * A signal occurred before any data was transmitted. 1340 * EINVAL 1341 * Invalid argument passed. 1342 * EISCONN 1343 * The connection-mode socket was connected already but a recipient 1344 * was specified. (Now either this error is returned, or the recipient 1345 * specification is ignored.) 1346 * EMSGSIZE 1347 * The socket type requires that message be sent atomically, and the 1348 * size of the message to be sent made this impossible. 1349 * ENOBUFS 1350 * The output queue for a network interface was full. This generally 1351 * indicates that the interface has stopped sending, but may be 1352 * caused by transient congestion. 1353 * ENOMEM 1354 * No memory available. 1355 * ENOTCONN 1356 * The socket is not connected, and no target has been given. 1357 * ENOTSOCK 1358 * The argument s is not a socket. 1359 * EOPNOTSUPP 1360 * Some bit in the flags argument is inappropriate for the socket 1361 * type. 1362 * EPIPE 1363 * The local end has been shut down on a connection oriented socket. 1364 * In this case the process will also receive a SIGPIPE unless 1365 * MSG_NOSIGNAL is set. 1366 * 1367 ****************************************************************************/ 1368 1369 #ifdef CONFIG_NET_SENDFILE 1370 struct file; 1371 ssize_t net_sendfile(int outfd, struct file *infile, off_t *offset, 1372 size_t count); 1373 #endif 1374 1375 /**************************************************************************** 1376 * Name: psock_vfcntl 1377 * 1378 * Description: 1379 * Performs fcntl operations on socket 1380 * 1381 * Input Parameters: 1382 * psock - An instance of the internal socket structure. 1383 * cmd - The fcntl command. 1384 * ap - Command-specific arguments 1385 * 1386 * Returned Value: 1387 * Zero (OK) is returned on success; a negated errno value is returned on 1388 * any failure to indicate the nature of the failure. 1389 * 1390 ****************************************************************************/ 1391 1392 int psock_vfcntl(FAR struct socket *psock, int cmd, va_list ap); 1393 1394 /**************************************************************************** 1395 * Name: psock_fcntl 1396 * 1397 * Description: 1398 * Similar to the standard fcntl function except that is accepts a struct 1399 * struct socket instance instead of a file descriptor. 1400 * 1401 * Input Parameters: 1402 * psock - An instance of the internal socket structure. 1403 * cmd - Identifies the operation to be performed. Command specific 1404 * arguments may follow. 1405 * 1406 * Returned Value: 1407 * The nature of the return value depends on the command. Non-negative 1408 * values indicate success. Failures are reported as negated errno 1409 * values. 1410 * 1411 ****************************************************************************/ 1412 1413 int psock_fcntl(FAR struct socket *psock, int cmd, ...); 1414 1415 /**************************************************************************** 1416 * Name: net_vfcntl 1417 * 1418 * Description: 1419 * Performs fcntl operations on socket 1420 * 1421 * Input Parameters: 1422 * sockfd - Socket descriptor of the socket to operate on 1423 * cmd - The fcntl command. 1424 * ap - Command-specific arguments 1425 * 1426 * Returned Value: 1427 * Zero (OK) is returned on success; a negated errno value is returned on 1428 * any failure to indicate the nature of the failure. 1429 * 1430 ****************************************************************************/ 1431 1432 int net_vfcntl(int sockfd, int cmd, va_list ap); 1433 1434 /**************************************************************************** 1435 * Name: netdev_register 1436 * 1437 * Description: 1438 * Register a network device driver and assign a name to it so that it can 1439 * be found in subsequent network ioctl operations on the device. 1440 * 1441 * A custom, device-specific interface name format string may be selected 1442 * by putting that format string into the device structure's d_ifname[] 1443 * array before calling netdev_register(). Otherwise, the d_ifname[] must 1444 * be zeroed on entry. 1445 * 1446 * Input Parameters: 1447 * dev - The device driver structure to be registered. 1448 * lltype - Link level protocol used by the driver (Ethernet, SLIP, TUN, ... 1449 * 1450 * Returned Value: 1451 * 0:Success; negated errno on failure 1452 * 1453 * Assumptions: 1454 * Called during system initialization from normal user mode 1455 * 1456 ****************************************************************************/ 1457 1458 int netdev_register(struct net_driver_s *dev, enum net_lltype_e lltype); 1459 1460 /**************************************************************************** 1461 * Name: netdev_unregister 1462 * 1463 * Description: 1464 * Unregister a network device driver. 1465 * 1466 * Input Parameters: 1467 * dev - The device driver structure to un-register 1468 * 1469 * Returned Value: 1470 * 0:Success; negated errno on failure 1471 * 1472 * Assumptions: 1473 * Currently only called for USB networking devices when the device is 1474 * physically removed from the slot 1475 * 1476 ****************************************************************************/ 1477 1478 int netdev_unregister(struct net_driver_s *dev); 1479 1480 1481 #ifdef __cplusplus 1482 #if __cplusplus 1483 } 1484 #endif /* __cplusplus */ 1485 #endif /* __cplusplus */ 1486 1487 #endif /* CONFIG_NET */ 1488 #endif /* __INCLUDE_NET_NET_H */ 1489