Changeset 0c37135 in mainline for uspace/lib
- Timestamp:
- 2012-04-18T07:32:58Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 5f67cd61
- Parents:
- 3d93289a (diff), 63920b0 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - Location:
- uspace/lib
- Files:
-
- 6 added
- 51 deleted
- 8 edited
- 6 moved
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/Makefile
r3d93289a r0c37135 87 87 generic/task.c \ 88 88 generic/futex.c \ 89 generic/inet.c \ 90 generic/inetcfg.c \ 91 generic/inetping.c \ 89 92 generic/io/asprintf.c \ 90 93 generic/io/io.c \ … … 97 100 generic/io/printf_core.c \ 98 101 generic/io/console.c \ 102 generic/iplink.c \ 103 generic/iplink_srv.c \ 99 104 generic/malloc.c \ 100 105 generic/sysinfo.c \ … … 108 113 generic/adt/hash_set.c \ 109 114 generic/adt/dynamic_fifo.c \ 110 generic/adt/measured_strings.c \111 115 generic/adt/char_map.c \ 112 116 generic/adt/prodcons.c \ … … 118 122 generic/vfs/canonify.c \ 119 123 generic/net/inet.c \ 120 generic/net/icmp_common.c \121 generic/net/icmp_api.c \122 124 generic/net/modules.c \ 123 generic/net/packet.c \124 125 generic/net/socket_client.c \ 125 126 generic/net/socket_parse.c \ -
uspace/lib/c/generic/io/printf_core.c
r3d93289a r0c37135 283 283 /* Print leading spaces. */ 284 284 size_t strw = str_length(str); 285 if ( precision == 0)285 if ((precision == 0) || (precision > strw)) 286 286 precision = strw; 287 287 … … 331 331 /* Print leading spaces. */ 332 332 size_t strw = wstr_length(str); 333 if ( precision == 0)333 if ((precision == 0) || (precision > strw)) 334 334 precision = strw; 335 335 -
uspace/lib/c/include/inet/inet.h
r3d93289a r0c37135 1 1 /* 2 * Copyright (c) 20 09 Lukas Mejdrech2 * Copyright (c) 2012 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 27 27 */ 28 28 29 /** @addtogroup lib net29 /** @addtogroup libc 30 30 * @{ 31 31 */ 32 33 32 /** @file 34 * Hardware types according to the on-line IANA - Address Resolution Protocol35 * (ARP) Parameters36 * http://www.iana.org/assignments/arp-parameters/arp-parameters.xml,37 * cited January 14 2009.38 33 */ 39 34 40 #ifndef LIB NET_NET_HARDWARE_H_41 #define LIB NET_NET_HARDWARE_H_35 #ifndef LIBC_INET_INET_H_ 36 #define LIBC_INET_INET_H_ 42 37 43 38 #include <sys/types.h> 44 39 45 /** Network interface layer type type definition. */ 46 typedef uint8_t hw_type_t; 40 #define INET_TTL_MAX 255 47 41 48 /** @name Network interface layer types definitions */ 49 /*@{*/ 42 typedef struct { 43 uint32_t ipv4; 44 } inet_addr_t; 50 45 51 /** Ethernet (10Mb) hardware type. */ 52 #define HW_ETHER 1 46 typedef struct { 47 inet_addr_t src; 48 inet_addr_t dest; 49 uint8_t tos; 50 void *data; 51 size_t size; 52 } inet_dgram_t; 53 53 54 /*@}*/ 54 typedef struct { 55 int (*recv)(inet_dgram_t *); 56 } inet_ev_ops_t; 57 58 typedef enum { 59 INET_DF = 1 60 } inet_df_t; 61 62 extern int inet_init(uint8_t, inet_ev_ops_t *); 63 extern int inet_send(inet_dgram_t *, uint8_t, inet_df_t); 64 extern int inet_get_srcaddr(inet_addr_t *, uint8_t, inet_addr_t *); 55 65 56 66 #endif … … 58 68 /** @} 59 69 */ 60 -
uspace/lib/c/include/inet/inetping.h
r3d93289a r0c37135 1 1 /* 2 * Copyright (c) 20 09 Lukas Mejdrech2 * Copyright (c) 2012 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 28 28 29 29 /** @addtogroup libc 30 * @{ 30 * @{ 31 */ 32 /** @file 31 33 */ 32 34 33 /** @file 34 * ICMP common interface implementation. 35 * @see icmp_common.h 36 */ 35 #ifndef LIBC_INET_INETPING_H_ 36 #define LIBC_INET_INETPING_H_ 37 37 38 #include <net/modules.h> 39 #include <net/icmp_common.h> 40 #include <ipc/services.h> 41 #include <ipc/icmp.h> 42 #include <sys/time.h> 43 #include <async.h> 38 #include <inet/inet.h> 39 #include <sys/types.h> 44 40 45 /** Connect to the ICMP module. 46 * 47 * @return ICMP module session. 48 * 49 */ 50 async_sess_t *icmp_connect_module(void) 51 { 52 return connect_to_service(SERVICE_ICMP); 53 } 41 typedef struct { 42 inet_addr_t src; 43 inet_addr_t dest; 44 uint16_t seq_no; 45 void *data; 46 size_t size; 47 } inetping_sdu_t; 48 49 typedef struct inetping_ev_ops { 50 int (*recv)(inetping_sdu_t *); 51 } inetping_ev_ops_t; 52 53 extern int inetping_init(inetping_ev_ops_t *); 54 extern int inetping_send(inetping_sdu_t *); 55 extern int inetping_get_srcaddr(inet_addr_t *, inet_addr_t *); 56 57 58 #endif 54 59 55 60 /** @} -
uspace/lib/c/include/inet/iplink.h
r3d93289a r0c37135 1 1 /* 2 * Copyright (c) 20 09 Lukas Mejdrech2 * Copyright (c) 2012 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 27 27 */ 28 28 29 /** @addtogroup libnet 30 * @{ 29 /** @addtogroup libc 30 * @{ 31 */ 32 /** @file 31 33 */ 32 34 33 #ifndef LIB NET_ICMP_REMOTE_H_34 #define LIB NET_ICMP_REMOTE_H_35 #ifndef LIBC_INET_IPLINK_H_ 36 #define LIBC_INET_IPLINK_H_ 35 37 36 #include < net/socket_codes.h>38 #include <async.h> 37 39 #include <sys/types.h> 38 #include <net/device.h>39 #include <adt/measured_strings.h>40 #include <net/packet.h>41 #include <net/inet.h>42 #include <net/ip_codes.h>43 #include <net/icmp_codes.h>44 #include <net/icmp_common.h>45 #include <async.h>46 40 47 /** @name ICMP module interface 48 * This interface is used by other modules. 49 */ 50 /*@{*/ 41 struct iplink_ev_ops; 51 42 52 extern int icmp_destination_unreachable_msg(async_sess_t *, icmp_code_t, 53 icmp_param_t, packet_t *); 54 extern int icmp_source_quench_msg(async_sess_t *, packet_t *); 55 extern int icmp_time_exceeded_msg(async_sess_t *, icmp_code_t, packet_t *); 56 extern int icmp_parameter_problem_msg(async_sess_t *, icmp_code_t, icmp_param_t, 57 packet_t *); 43 typedef struct { 44 async_sess_t *sess; 45 struct iplink_ev_ops *ev_ops; 46 } iplink_t; 58 47 59 /*@}*/ 48 typedef struct { 49 uint32_t ipv4; 50 } iplink_addr_t; 51 52 /** IP link Service Data Unit */ 53 typedef struct { 54 /** Local source address */ 55 iplink_addr_t lsrc; 56 /** Local destination address */ 57 iplink_addr_t ldest; 58 /** Serialized IP packet */ 59 void *data; 60 /** Size of @c data in bytes */ 61 size_t size; 62 } iplink_sdu_t; 63 64 typedef struct iplink_ev_ops { 65 int (*recv)(iplink_t *, iplink_sdu_t *); 66 } iplink_ev_ops_t; 67 68 extern int iplink_open(async_sess_t *, iplink_ev_ops_t *, iplink_t **); 69 extern void iplink_close(iplink_t *); 70 extern int iplink_send(iplink_t *, iplink_sdu_t *); 71 extern int iplink_addr_add(iplink_t *, iplink_addr_t *); 72 extern int iplink_addr_remove(iplink_t *, iplink_addr_t *); 73 extern int iplink_get_mtu(iplink_t *, size_t *); 60 74 61 75 #endif -
uspace/lib/c/include/inet/iplink_srv.h
r3d93289a r0c37135 1 1 /* 2 * Copyright (c) 20 09 Lukas Mejdrech2 * Copyright (c) 2012 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 28 28 29 29 /** @addtogroup libc 30 * @{ 30 * @{ 31 */ 32 /** @file 31 33 */ 32 34 33 /** @file 34 * Character string with measured length. 35 * The structure has been designed for serialization of character strings 36 * between modules. 37 */ 35 #ifndef LIBC_INET_IPLINK_SRV_H_ 36 #define LIBC_INET_IPLINK_SRV_H_ 38 37 39 #ifndef LIBC_MEASURED_STRINGS_H_ 40 #define LIBC_MEASURED_STRINGS_H_ 38 #include <async.h> 39 #include <fibril_synch.h> 40 #include <bool.h> 41 #include <sys/types.h> 41 42 42 #include <sys/types.h> 43 #include <async.h> 43 struct iplink_ops; 44 44 45 /** Type definition of the character string with measured length. 46 * @see measured_string 47 */ 48 typedef struct measured_string measured_string_t; 45 typedef struct { 46 fibril_mutex_t lock; 47 bool connected; 48 struct iplink_ops *ops; 49 void *arg; 50 async_sess_t *client_sess; 51 } iplink_srv_t; 49 52 50 /** Character string with measured length. 51 * 52 * This structure has been designed for serialization of character strings 53 * between modules. 54 */ 55 struct measured_string { 56 /** Character string data. */ 57 uint8_t *value; 58 /** Character string length. */ 59 size_t length; 60 }; 53 typedef struct { 54 uint32_t ipv4; 55 } iplink_srv_addr_t; 61 56 62 extern measured_string_t *measured_string_create_bulk(const uint8_t *, size_t); 63 extern measured_string_t *measured_string_copy(measured_string_t *); 57 /** IP link Service Data Unit */ 58 typedef struct { 59 /** Local source address */ 60 iplink_srv_addr_t lsrc; 61 /** Local destination address */ 62 iplink_srv_addr_t ldest; 63 /** Serialized IP packet */ 64 void *data; 65 /** Size of @c data in bytes */ 66 size_t size; 67 } iplink_srv_sdu_t; 64 68 65 extern int measured_strings_receive(measured_string_t **, uint8_t **, size_t); 66 extern int measured_strings_reply(const measured_string_t *, size_t); 69 typedef struct iplink_ops { 70 int (*open)(iplink_srv_t *); 71 int (*close)(iplink_srv_t *); 72 int (*send)(iplink_srv_t *, iplink_srv_sdu_t *); 73 int (*get_mtu)(iplink_srv_t *, size_t *); 74 int (*addr_add)(iplink_srv_t *, iplink_srv_addr_t *); 75 int (*addr_remove)(iplink_srv_t *, iplink_srv_addr_t *); 76 } iplink_ops_t; 67 77 68 extern int measured_strings_return(async_exch_t *, measured_string_t **,69 uint8_t **, size_t); 70 extern int measured_strings_send(async_exch_t *, const measured_string_t *,71 size_t);78 extern void iplink_srv_init(iplink_srv_t *); 79 80 extern int iplink_conn(ipc_callid_t, ipc_call_t *, void *); 81 extern int iplink_ev_recv(iplink_srv_t *, iplink_srv_sdu_t *); 72 82 73 83 #endif -
uspace/lib/c/include/ipc/inet.h
r3d93289a r0c37135 1 1 /* 2 * Copyright (c) 2009 Lukas Mejdrech 3 * Copyright (c) 2011 Radim Vansa 2 * Copyright (c) 2012 Jiri Svoboda 4 3 * All rights reserved. 5 4 * … … 28 27 */ 29 28 30 /** @addtogroup lib packet29 /** @addtogroup libcipc 31 30 * @{ 32 31 */ 33 34 32 /** @file 35 * Packet server.36 * The hosting module has to be compiled with both the packet.c and the37 * packet_server.c source files. To function correctly, initialization of the38 * packet map by the pm_init() function has to happen at the first place. Then39 * the packet messages have to be processed by the packet_server_message()40 * function. The packet map should be released by the pm_destroy() function41 * during the module termination.42 * @see IS_NET_PACKET_MESSAGE()43 33 */ 44 34 45 #ifndef NET_PACKET_SERVER_H_46 #define NET_PACKET_SERVER_H_35 #ifndef LIBC_IPC_INET_H_ 36 #define LIBC_IPC_INET_H_ 47 37 48 38 #include <ipc/common.h> 49 39 50 extern int packet_server_init(void); 51 extern int packet_server_message(ipc_callid_t, ipc_call_t *, ipc_call_t *, 52 size_t *); 40 /** Inet ports */ 41 typedef enum { 42 /** Default port */ 43 INET_PORT_DEFAULT = 1, 44 /** Configuration port */ 45 INET_PORT_CFG, 46 /** Ping service port */ 47 INET_PORT_PING 48 } inet_port_t; 49 50 /** Requests on Inet default port */ 51 typedef enum { 52 INET_CALLBACK_CREATE = IPC_FIRST_USER_METHOD, 53 INET_GET_SRCADDR, 54 INET_SEND, 55 INET_SET_PROTO 56 } inet_request_t; 57 58 /** Events on Inet default port */ 59 typedef enum { 60 INET_EV_RECV = IPC_FIRST_USER_METHOD 61 } inet_event_t; 62 63 /** Requests on Inet configuration port */ 64 typedef enum { 65 INETCFG_ADDR_CREATE_STATIC = IPC_FIRST_USER_METHOD, 66 INETCFG_ADDR_DELETE, 67 INETCFG_ADDR_GET, 68 INETCFG_ADDR_GET_ID, 69 INETCFG_GET_ADDR_LIST, 70 INETCFG_GET_LINK_LIST, 71 INETCFG_GET_SROUTE_LIST, 72 INETCFG_LINK_GET, 73 INETCFG_SROUTE_CREATE, 74 INETCFG_SROUTE_DELETE, 75 INETCFG_SROUTE_GET, 76 INETCFG_SROUTE_GET_ID 77 } inetcfg_request_t; 78 79 /** Events on Inet ping port */ 80 typedef enum { 81 INETPING_EV_RECV = IPC_FIRST_USER_METHOD 82 } inetping_event_t; 83 84 /** Requests on Inet ping port */ 85 typedef enum { 86 INETPING_SEND = IPC_FIRST_USER_METHOD, 87 INETPING_GET_SRCADDR 88 } inetping_request_t; 53 89 54 90 #endif 55 91 56 /** @} 92 /** 93 * @} 57 94 */ -
uspace/lib/c/include/ipc/iplink.h
r3d93289a r0c37135 1 1 /* 2 * Copyright (c) 20 09 Lukas Mejdrech2 * Copyright (c) 2012 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 27 27 */ 28 28 29 /** @addtogroup libc 29 /** @addtogroup libcipc 30 30 * @{ 31 31 */ 32 33 32 /** @file 34 * Transport layer modules messages.35 * @see tl_interface.h36 33 */ 37 34 38 #ifndef LIBC_ TL_MESSAGES_H_39 #define LIBC_ TL_MESSAGES_H_35 #ifndef LIBC_IPC_IPLINK_H_ 36 #define LIBC_IPC_IPLINK_H_ 40 37 41 #include <ipc/ net.h>38 #include <ipc/common.h> 42 39 43 /** Transport layer modules messages. */44 40 typedef enum { 45 /** Packet received message. 46 * @see tl_received_msg() 47 */ 48 NET_TL_RECEIVED = NET_TL_FIRST 49 } tl_messages; 41 IPLINK_GET_MTU = IPC_FIRST_USER_METHOD, 42 IPLINK_SEND, 43 IPLINK_ADDR_ADD, 44 IPLINK_ADDR_REMOVE 45 } iplink_request_t; 46 47 typedef enum { 48 IPLINK_EV_RECV = IPC_FIRST_USER_METHOD 49 } iplink_event_t; 50 50 51 51 #endif 52 52 53 /** @} 53 /** 54 * @} 54 55 */ -
uspace/lib/c/include/ipc/services.h
r3d93289a r0c37135 48 48 SERVICE_IRC = FOURCC('i', 'r', 'c', ' '), 49 49 SERVICE_CLIPBOARD = FOURCC('c', 'l', 'i', 'p'), 50 SERVICE_NETWORKING = FOURCC('n', 'e', 't', ' '),51 SERVICE_ETHERNET = FOURCC('e', 't', 'h', ' '),52 SERVICE_NILDUMMY = FOURCC('n', 'i', 'l', 'd'),53 SERVICE_IP = FOURCC('i', 'p', 'v', '4'),54 SERVICE_ARP = FOURCC('a', 'r', 'p', ' '),55 SERVICE_ICMP = FOURCC('i', 'c', 'm', 'p'),56 50 SERVICE_UDP = FOURCC('u', 'd', 'p', ' '), 57 51 SERVICE_TCP = FOURCC('t', 'c', 'p', ' ') 58 52 } services_t; 53 54 #define SERVICE_NAME_INET "net/inet" 55 #define SERVICE_NAME_INETCFG "net/inetcfg" 56 #define SERVICE_NAME_INETPING "net/inetping" 59 57 60 58 #endif -
uspace/lib/c/include/ipc/socket.h
r3d93289a r0c37135 38 38 #define LIBC_SOCKET_MESSAGES_H_ 39 39 40 #include <ipc/net.h>41 42 40 /** Socket client messages. */ 43 41 typedef enum { 44 42 /** Creates a new socket. @see socket() */ 45 NET_SOCKET = NET_SOCKET_FIRST,43 NET_SOCKET = IPC_FIRST_USER_METHOD, 46 44 /** Binds the socket. @see bind() */ 47 45 NET_SOCKET_BIND, -
uspace/lib/c/include/net/in.h
r3d93289a r0c37135 45 45 #define INET_ADDRSTRLEN (4 * 3 + 3 + 1) 46 46 47 #define INADDR_ANY 0 48 47 49 /** Type definition of the INET address. 48 50 * @see in_addr -
uspace/lib/net/Makefile
r3d93289a r0c37135 33 33 34 34 SOURCES = \ 35 generic/generic.c \ 36 generic/net_remote.c \ 37 generic/net_checksum.c \ 38 generic/packet_client.c \ 39 generic/packet_remote.c \ 40 generic/protocol_map.c \ 41 adt/module_map.c \ 42 nil/nil_remote.c \ 43 nil/nil_skel.c \ 44 il/il_remote.c \ 45 il/il_skel.c \ 46 il/ip_remote.c \ 47 il/ip_client.c \ 48 il/arp_remote.c \ 49 tl/icmp_remote.c \ 50 tl/icmp_client.c \ 51 tl/socket_core.c \ 52 tl/tl_common.c \ 53 tl/tl_remote.c \ 54 tl/tl_skel.c 35 tl/socket_core.c 55 36 56 37 include $(USPACE_PREFIX)/Makefile.common -
uspace/lib/net/include/socket_core.h
r3d93289a r0c37135 44 44 #include <net/in.h> 45 45 #include <net/device.h> 46 #include <net/packet.h>47 46 #include <async.h> 48 47 … … 80 79 /** Bound port. */ 81 80 int port; 82 /** Received packets queue. */83 dyn_fifo_t received;84 81 /** Sockets for acceptance queue. */ 85 82 dyn_fifo_t accepted; … … 118 115 extern int socket_destroy(async_sess_t *, int, socket_cores_t *, 119 116 socket_ports_t *, void (*)(socket_core_t *)); 120 extern int socket_reply_packets(packet_t *, size_t *);121 117 extern socket_core_t *socket_port_find(socket_ports_t *, int, const uint8_t *, 122 118 size_t); -
uspace/lib/net/tl/socket_core.c
r3d93289a r0c37135 36 36 37 37 #include <socket_core.h> 38 #include <packet_client.h>39 #include <packet_remote.h>40 38 #include <net/socket_codes.h> 41 39 #include <net/in.h> 42 40 #include <net/inet.h> 43 #include <net/packet.h>44 41 #include <net/modules.h> 45 42 #include <stdint.h> … … 92 89 } 93 90 94 /* Release all received packets */95 int packet_id;96 while ((packet_id = dyn_fifo_pop(&socket->received)) >= 0)97 pq_release_remote(sess, packet_id);98 99 dyn_fifo_destroy(&socket->received);100 91 dyn_fifo_destroy(&socket->accepted); 101 92 … … 448 439 socket->key_length = 0; 449 440 socket->specific_data = specific_data; 450 rc = dyn_fifo_initialize(&socket->received, SOCKET_INITIAL_RECEIVED_SIZE); 441 442 rc = dyn_fifo_initialize(&socket->accepted, SOCKET_INITIAL_ACCEPTED_SIZE); 451 443 if (rc != EOK) { 452 444 free(socket); 453 445 return rc; 454 446 } 455 456 rc = dyn_fifo_initialize(&socket->accepted, SOCKET_INITIAL_ACCEPTED_SIZE);457 if (rc != EOK) {458 dyn_fifo_destroy(&socket->received);459 free(socket);460 return rc;461 }462 447 socket->socket_id = *socket_id; 463 448 rc = socket_cores_add(local_sockets, socket->socket_id, socket); 464 449 if (rc < 0) { 465 dyn_fifo_destroy(&socket->received);466 450 dyn_fifo_destroy(&socket->accepted); 467 451 free(socket); … … 506 490 socket_destroy_core(sess, socket, local_sockets, global_sockets, 507 491 socket_release); 508 509 return EOK;510 }511 512 /** Replies the packet or the packet queue data to the application via the513 * socket.514 *515 * Uses the current message processing fibril.516 *517 * @param[in] packet The packet to be transfered.518 * @param[out] length The total data length.519 * @return EOK on success.520 * @return EBADMEM if the length parameter is NULL.521 * @return ENOMEM if there is not enough memory left.522 * @return Other error codes as defined for the data_reply()523 * function.524 */525 int socket_reply_packets(packet_t *packet, size_t *length)526 {527 packet_t *next_packet;528 size_t fragments;529 size_t *lengths;530 size_t index;531 int rc;532 533 if (!length)534 return EBADMEM;535 536 next_packet = pq_next(packet);537 if (!next_packet) {538 /* Write all if only one fragment */539 rc = data_reply(packet_get_data(packet),540 packet_get_data_length(packet));541 if (rc != EOK)542 return rc;543 /* Store the total length */544 *length = packet_get_data_length(packet);545 } else {546 /* Count the packet fragments */547 fragments = 1;548 next_packet = pq_next(packet);549 while ((next_packet = pq_next(next_packet)))550 ++fragments;551 552 /* Compute and store the fragment lengths */553 lengths = (size_t *) malloc(sizeof(size_t) * fragments +554 sizeof(size_t));555 if (!lengths)556 return ENOMEM;557 558 lengths[0] = packet_get_data_length(packet);559 lengths[fragments] = lengths[0];560 next_packet = pq_next(packet);561 562 for (index = 1; index < fragments; ++index) {563 lengths[index] = packet_get_data_length(next_packet);564 lengths[fragments] += lengths[index];565 next_packet = pq_next(packet);566 }567 568 /* Write the fragment lengths */569 rc = data_reply(lengths, sizeof(int) * (fragments + 1));570 if (rc != EOK) {571 free(lengths);572 return rc;573 }574 next_packet = packet;575 576 /* Write the fragments */577 for (index = 0; index < fragments; ++index) {578 rc = data_reply(packet_get_data(next_packet),579 lengths[index]);580 if (rc != EOK) {581 free(lengths);582 return rc;583 }584 next_packet = pq_next(next_packet);585 }586 587 /* Store the total length */588 *length = lengths[fragments];589 free(lengths);590 }591 492 592 493 return EOK;
Note:
See TracChangeset
for help on using the changeset viewer.