Index: uspace/srv/net/tl/udp/udp.c
===================================================================
--- uspace/srv/net/tl/udp/udp.c	(revision 6b8200979d8daac47bccc812f910bbf881df8e94)
+++ uspace/srv/net/tl/udp/udp.c	(revision afe1d1e203e5c589222f7579368f84a24d325f3c)
@@ -99,5 +99,5 @@
 static int udp_release_and_return(packet_t *packet, int result)
 {
-	pq_release_remote(udp_globals.net_sess, packet_get_id(packet));
+	pq_release_remote(udp_globals.net_phone, packet_get_id(packet));
 	return result;
 }
@@ -192,7 +192,7 @@
 	    ntohs(header->destination_port), (uint8_t *) SOCKET_MAP_KEY_LISTENING, 0);
 	if (!socket) {
-		if (tl_prepare_icmp_packet(udp_globals.net_sess,
-		    udp_globals.icmp_sess, packet, error) == EOK) {
-			icmp_destination_unreachable_msg(udp_globals.icmp_sess,
+		if (tl_prepare_icmp_packet(udp_globals.net_phone,
+		    udp_globals.icmp_phone, packet, error) == EOK) {
+			icmp_destination_unreachable_msg(udp_globals.icmp_phone,
 			    ICMP_PORT_UNREACH, 0, packet);
 		}
@@ -251,5 +251,5 @@
 			while (tmp_packet) {
 				next_packet = pq_detach(tmp_packet);
-				pq_release_remote(udp_globals.net_sess,
+				pq_release_remote(udp_globals.net_phone,
 				    packet_get_id(tmp_packet));
 				tmp_packet = next_packet;
@@ -274,9 +274,9 @@
 		if (flip_checksum(compact_checksum(checksum)) !=
 		    IP_CHECKSUM_ZERO) {
-			if (tl_prepare_icmp_packet(udp_globals.net_sess,
-			    udp_globals.icmp_sess, packet, error) == EOK) {
+			if (tl_prepare_icmp_packet(udp_globals.net_phone,
+			    udp_globals.icmp_phone, packet, error) == EOK) {
 				/* Checksum error ICMP */
 				icmp_parameter_problem_msg(
-				    udp_globals.icmp_sess, ICMP_PARAM_POINTER,
+				    udp_globals.icmp_phone, ICMP_PARAM_POINTER,
 				    ((size_t) ((void *) &header->checksum)) -
 				    ((size_t) ((void *) header)), packet);
@@ -292,5 +292,5 @@
 		return udp_release_and_return(packet, rc);
 		
-	rc = tl_get_ip_packet_dimension(udp_globals.ip_sess,
+	rc = tl_get_ip_packet_dimension(udp_globals.ip_phone,
 	    &udp_globals.dimensions, device_id, &packet_dimension);
 	if (rc != EOK)
@@ -299,9 +299,7 @@
 	/* Notify the destination socket */
 	fibril_rwlock_write_unlock(&udp_globals.lock);
-	
-	async_exch_t *exch = async_exchange_begin(socket->sess);
-	async_msg_5(exch, NET_SOCKET_RECEIVED, (sysarg_t) socket->socket_id,
-	    packet_dimension->content, 0, 0, (sysarg_t) fragments);
-	async_exchange_end(exch);
+	async_msg_5(socket->phone, NET_SOCKET_RECEIVED,
+	    (sysarg_t) socket->socket_id, packet_dimension->content, 0, 0,
+	    (sysarg_t) fragments);
 
 	return EOK;
@@ -339,8 +337,7 @@
  * @param[in]     iid   Message identifier.
  * @param[in,out] icall Message parameters.
- * @param[in]     arg   Local argument.
- *
- */
-static void udp_receiver(ipc_callid_t iid, ipc_call_t *icall, void *arg)
+ *
+ */
+static void udp_receiver(ipc_callid_t iid, ipc_call_t *icall)
 {
 	packet_t *packet;
@@ -350,5 +347,5 @@
 		switch (IPC_GET_IMETHOD(*icall)) {
 		case NET_TL_RECEIVED:
-			rc = packet_translate_remote(udp_globals.net_sess, &packet,
+			rc = packet_translate_remote(udp_globals.net_phone, &packet,
 			    IPC_GET_PACKET(*icall));
 			if (rc == EOK)
@@ -368,5 +365,5 @@
 /** Initialize the UDP module.
  *
- * @param[in] sess Network module session.
+ * @param[in] net_phone Network module phone.
  *
  * @return EOK on success.
@@ -374,5 +371,5 @@
  *
  */
-int tl_initialize(async_sess_t *sess)
+int tl_initialize(int net_phone)
 {
 	measured_string_t names[] = {
@@ -393,16 +390,17 @@
 	fibril_rwlock_write_lock(&udp_globals.lock);
 	
-	udp_globals.net_sess = sess;
-	udp_globals.icmp_sess = icmp_connect_module();
-	
-	udp_globals.ip_sess = ip_bind_service(SERVICE_IP, IPPROTO_UDP,
-	     SERVICE_UDP, udp_receiver);
-	if (udp_globals.ip_sess == NULL) {
-	    fibril_rwlock_write_unlock(&udp_globals.lock);
-	    return ENOENT;
+	udp_globals.net_phone = net_phone;
+	
+	udp_globals.icmp_phone = icmp_connect_module(ICMP_CONNECT_TIMEOUT);
+	
+	udp_globals.ip_phone = ip_bind_service(SERVICE_IP, IPPROTO_UDP,
+	    SERVICE_UDP, udp_receiver);
+	if (udp_globals.ip_phone < 0) {
+		fibril_rwlock_write_unlock(&udp_globals.lock);
+		return udp_globals.ip_phone;
 	}
 	
 	/* Read default packet dimensions */
-	int rc = ip_packet_size_req(udp_globals.ip_sess, -1,
+	int rc = ip_packet_size_req(udp_globals.ip_phone, -1,
 	    &udp_globals.packet_dimension);
 	if (rc != EOK) {
@@ -419,5 +417,5 @@
 	rc = packet_dimensions_initialize(&udp_globals.dimensions);
 	if (rc != EOK) {
-		socket_ports_destroy(&udp_globals.sockets, free);
+		socket_ports_destroy(&udp_globals.sockets);
 		fibril_rwlock_write_unlock(&udp_globals.lock);
 		return rc;
@@ -433,8 +431,8 @@
 	/* Get configuration */
 	configuration = &names[0];
-	rc = net_get_conf_req(udp_globals.net_sess, &configuration, count,
+	rc = net_get_conf_req(udp_globals.net_phone, &configuration, count,
 	    &data);
 	if (rc != EOK) {
-		socket_ports_destroy(&udp_globals.sockets, free);
+		socket_ports_destroy(&udp_globals.sockets);
 		fibril_rwlock_write_unlock(&udp_globals.lock);
 		return rc;
@@ -501,9 +499,5 @@
 	device_id_t device_id;
 	packet_dimension_t *packet_dimension;
-	size_t size;
 	int rc;
-
-	/* In case of error, do not update the data fragment size. */
-	*data_fragment_size = 0;
 	
 	rc = tl_get_address_port(addr, addrlen, &dest_port);
@@ -527,10 +521,10 @@
 
 	if (udp_globals.checksum_computing) {
-		rc = ip_get_route_req(udp_globals.ip_sess, IPPROTO_UDP, addr,
+		rc = ip_get_route_req(udp_globals.ip_phone, IPPROTO_UDP, addr,
 		    addrlen, &device_id, &ip_header, &headerlen);
 		if (rc != EOK)
 			return rc;
 		/* Get the device packet dimension */
-//		rc = tl_get_ip_packet_dimension(udp_globals.ip_sess,
+//		rc = tl_get_ip_packet_dimension(udp_globals.ip_phone,
 //		    &udp_globals.dimensions, device_id, &packet_dimension);
 //		if (rc != EOK)
@@ -539,5 +533,5 @@
 //	} else {
 		/* Do not ask all the time */
-		rc = ip_packet_size_req(udp_globals.ip_sess, -1,
+		rc = ip_packet_size_req(udp_globals.ip_phone, -1,
 		    &udp_globals.packet_dimension);
 		if (rc != EOK)
@@ -546,16 +540,6 @@
 //	}
 
-	/*
-	 * Update the data fragment size based on what the lower layers can
-	 * handle without fragmentation, but not more than the maximum allowed
-	 * for UDP.
-	 */
-	size = MAX_UDP_FRAGMENT_SIZE;
-	if (packet_dimension->content < size)
-	    size = packet_dimension->content;
-	*data_fragment_size = size;
-
 	/* Read the first packet fragment */
-	result = tl_socket_read_packet_data(udp_globals.net_sess, &packet,
+	result = tl_socket_read_packet_data(udp_globals.net_phone, &packet,
 	    UDP_HEADER_SIZE, packet_dimension, addr, addrlen);
 	if (result < 0)
@@ -578,5 +562,5 @@
 	/* Read the rest of the packet fragments */
 	for (index = 1; index < fragments; index++) {
-		result = tl_socket_read_packet_data(udp_globals.net_sess,
+		result = tl_socket_read_packet_data(udp_globals.net_phone,
 		    &next_packet, 0, packet_dimension, addr, addrlen);
 		if (result < 0)
@@ -630,5 +614,5 @@
 
 	/* Send the packet */
-	ip_send_msg(udp_globals.ip_sess, device_id, packet, SERVICE_UDP, 0);
+	ip_send_msg(udp_globals.ip_phone, device_id, packet, SERVICE_UDP, 0);
 
 	return EOK;
@@ -677,5 +661,5 @@
 		return NO_DATA;
 	
-	rc = packet_translate_remote(udp_globals.net_sess, &packet, packet_id);
+	rc = packet_translate_remote(udp_globals.net_phone, &packet, packet_id);
 	if (rc != EOK) {
 		(void) dyn_fifo_pop(&socket->received);
@@ -737,26 +721,24 @@
 }
 
-/** Process the socket client messages.
- *
- * Run until the client module disconnects.
- *
- * @see socket.h
- *
- * @param[in] sess   Callback session.
- * @param[in] callid Message identifier.
- * @param[in] call   Message parameters.
- *
- * @return EOK on success.
- *
- */
-static int udp_process_client_messages(async_sess_t *sess, ipc_callid_t callid,
-    ipc_call_t call)
+/** Processes the socket client messages.
+ *
+ * Runs until the client module disconnects.
+ *
+ * @param[in] callid 	The message identifier.
+ * @param[in] call	The message parameters.
+ * @return		EOK on success.
+ *
+ * @see	socket.h
+ */
+static int udp_process_client_messages(ipc_callid_t callid, ipc_call_t call)
 {
 	int res;
+	bool keep_on_going = true;
 	socket_cores_t local_sockets;
+	int app_phone = IPC_GET_PHONE(call);
 	struct sockaddr *addr;
 	int socket_id;
 	size_t addrlen;
-	size_t size;
+	size_t size = 0;
 	ipc_call_t answer;
 	size_t answer_count;
@@ -777,5 +759,5 @@
 	socket_cores_initialize(&local_sockets);
 
-	while (true) {
+	while (keep_on_going) {
 
 		/* Answer the call */
@@ -789,13 +771,13 @@
 
 		/* Process the call */
-		if (!IPC_GET_IMETHOD(call)) {
+		switch (IPC_GET_IMETHOD(call)) {
+		case IPC_M_PHONE_HUNGUP:
+			keep_on_going = false;
 			res = EHANGUP;
 			break;
-		}
-		
-		switch (IPC_GET_IMETHOD(call)) {
+
 		case NET_SOCKET:
 			socket_id = SOCKET_GET_SOCKET_ID(call);
-			res = socket_create(&local_sockets, sess, NULL,
+			res = socket_create(&local_sockets, app_phone, NULL,
 			    &socket_id);
 			SOCKET_SET_SOCKET_ID(answer, socket_id);
@@ -804,12 +786,13 @@
 				break;
 			
-			size = MAX_UDP_FRAGMENT_SIZE;
-			if (tl_get_ip_packet_dimension(udp_globals.ip_sess,
+			if (tl_get_ip_packet_dimension(udp_globals.ip_phone,
 			    &udp_globals.dimensions, DEVICE_INVALID_ID,
 			    &packet_dimension) == EOK) {
-				if (packet_dimension->content < size)
-					size = packet_dimension->content;
+				SOCKET_SET_DATA_FRAGMENT_SIZE(answer,
+				    packet_dimension->content);
 			}
-			SOCKET_SET_DATA_FRAGMENT_SIZE(answer, size);
+
+//			SOCKET_SET_DATA_FRAGMENT_SIZE(answer,
+//			    MAX_UDP_FRAGMENT_SIZE);
 			SOCKET_SET_HEADER_SIZE(answer, UDP_HEADER_SIZE);
 			answer_count = 3;
@@ -869,5 +852,5 @@
 		case NET_SOCKET_CLOSE:
 			fibril_rwlock_write_lock(&udp_globals.lock);
-			res = socket_destroy(udp_globals.net_sess,
+			res = socket_destroy(udp_globals.net_phone,
 			    SOCKET_GET_SOCKET_ID(call), &local_sockets,
 			    &udp_globals.sockets, NULL);
@@ -883,9 +866,9 @@
 	}
 
-	/* Release the application session */
-	async_hangup(sess);
+	/* Release the application phone */
+	async_hangup(app_phone);
 
 	/* Release all local sockets */
-	socket_cores_release(udp_globals.net_sess, &local_sockets,
+	socket_cores_release(udp_globals.net_phone, &local_sockets,
 	    &udp_globals.sockets, NULL);
 
@@ -917,10 +900,10 @@
 {
 	*answer_count = 0;
-	
-	async_sess_t *callback =
-	    async_callback_receive_start(EXCHANGE_SERIALIZE, call);
-	if (callback)
-		return udp_process_client_messages(callback, callid, *call);
-	
+
+	switch (IPC_GET_IMETHOD(*call)) {
+	case IPC_M_CONNECT_TO_ME:
+		return udp_process_client_messages(callid, *call);
+	}
+
 	return ENOTSUP;
 }
