Changeset 8e189ef in mainline


Ignore:
Timestamp:
2010-11-14T17:25:55Z (13 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
481b212
Parents:
982e3d8 (diff), a9db9b8 (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.
Message:

Merge mainline changes.

Files:
2 added
30 edited

Legend:

Unmodified
Added
Removed
  • kernel/arch/amd64/include/pm.h

    r982e3d8 r8e189ef  
    8383
    8484#define TSS_BASIC_SIZE  104
    85 #define TSS_IOMAP_SIZE  (16 * 1024 + 1)  /* 16K for bitmap + 1 terminating byte for convenience */
     85#define TSS_IOMAP_SIZE  (8 * 1024 + 1)  /* 8K for bitmap + 1 terminating byte for convenience */
    8686
    8787#define IO_PORTS  (64 * 1024)
  • kernel/arch/amd64/src/ddi/ddi.c

    r982e3d8 r8e189ef  
    126126                bitmap_initialize(&iomap, CPU->arch.tss->iomap,
    127127                    TSS_IOMAP_SIZE * 8);
    128                 bitmap_copy(&iomap, &TASK->arch.iomap, TASK->arch.iomap.bits);
     128                bitmap_copy(&iomap, &TASK->arch.iomap, bits);
    129129               
     130                /*
     131                 * Set the trailing bits in the last byte of the map to disable
     132                 * I/O access.
     133                 */
     134                bitmap_set_range(&iomap, bits, ALIGN_UP(bits, 8) - bits);
    130135                /*
    131136                 * It is safe to set the trailing eight bits because of the
    132137                 * extra convenience byte in TSS_IOMAP_SIZE.
    133138                 */
    134                 bitmap_set_range(&iomap, ALIGN_UP(TASK->arch.iomap.bits, 8), 8);
     139                bitmap_set_range(&iomap, ALIGN_UP(bits, 8), 8);
    135140        }
    136141        irq_spinlock_unlock(&TASK->lock, false);
  • kernel/arch/ia32/include/pm.h

    r982e3d8 r8e189ef  
    7575
    7676#define TSS_BASIC_SIZE  104
    77 #define TSS_IOMAP_SIZE  (16 * 1024 + 1)  /* 16K for bitmap + 1 terminating byte for convenience */
     77#define TSS_IOMAP_SIZE  (8 * 1024 + 1)  /* 8K for bitmap + 1 terminating byte for convenience */
    7878
    7979#define IO_PORTS  (64 * 1024)
  • kernel/arch/ia32/src/ddi/ddi.c

    r982e3d8 r8e189ef  
    127127                bitmap_initialize(&iomap, CPU->arch.tss->iomap,
    128128                    TSS_IOMAP_SIZE * 8);
    129                 bitmap_copy(&iomap, &TASK->arch.iomap, TASK->arch.iomap.bits);
     129                bitmap_copy(&iomap, &TASK->arch.iomap, bits);
    130130               
     131                /*
     132                 * Set the trailing bits in the last byte of the map to disable
     133                 * I/O access.
     134                 */
     135                bitmap_set_range(&iomap, bits, ALIGN_UP(bits, 8) - bits);
    131136                /*
    132137                 * It is safe to set the trailing eight bits because of the
    133138                 * extra convenience byte in TSS_IOMAP_SIZE.
    134139                 */
    135                 bitmap_set_range(&iomap, ALIGN_UP(TASK->arch.iomap.bits, 8), 8);
     140                bitmap_set_range(&iomap, ALIGN_UP(bits, 8), 8);
    136141        }
    137142        irq_spinlock_unlock(&TASK->lock, false);
  • kernel/generic/src/adt/bitmap.c

    r982e3d8 r8e189ef  
    3232/**
    3333 * @file
    34  * @brief       Implementation of bitmap ADT.
     34 * @brief Implementation of bitmap ADT.
    3535 *
    3636 * This file implements bitmap ADT and provides functions for
     
    5151 * No portion of the bitmap is set or cleared by this function.
    5252 *
    53  * @param bitmap Bitmap structure.
    54  * @param map Address of the memory used to hold the map.
    55  * @param bits Number of bits stored in bitmap.
     53 * @param bitmap        Bitmap structure.
     54 * @param map           Address of the memory used to hold the map.
     55 * @param bits          Number of bits stored in bitmap.
    5656 */
    5757void bitmap_initialize(bitmap_t *bitmap, uint8_t *map, size_t bits)
     
    6363/** Set range of bits.
    6464 *
    65  * @param bitmap Bitmap structure.
    66  * @param start Starting bit.
    67  * @param bits Number of bits to set.
     65 * @param bitmap        Bitmap structure.
     66 * @param start         Starting bit.
     67 * @param bits          Number of bits to set.
    6868 */
    6969void bitmap_set_range(bitmap_t *bitmap, size_t start, size_t bits)
     
    7171        size_t i = 0;
    7272        size_t aligned_start;
    73         size_t lub;             /* leading unaligned bits */
    74         size_t amb;             /* aligned middle bits */
    75         size_t tab;             /* trailing aligned bits */
     73        size_t lub;     /* leading unaligned bits */
     74        size_t amb;     /* aligned middle bits */
     75        size_t tab;     /* trailing aligned bits */
    7676       
    7777        ASSERT(start + bits <= bitmap->bits);
     
    8282        tab = amb % 8;
    8383       
    84         if ( start + bits < aligned_start ) {
    85             /*
    86             * Set bits in the middle of byte
    87             */
    88             bitmap->map[start / 8] |= ((1 << lub)-1) << (start&7);
    89             return;
     84        if (!bits)
     85                return;
     86
     87        if (start + bits < aligned_start) {
     88                /* Set bits in the middle of byte. */
     89                bitmap->map[start / 8] |= ((1 << lub) - 1) << (start & 7);
     90                return;
    9091        }
    9192       
    9293        if (lub) {
    93                 /*
    94                  * Make sure to set any leading unaligned bits.
    95                  */
     94                /* Make sure to set any leading unaligned bits. */
    9695                bitmap->map[start / 8] |= ~((1 << (8 - lub)) - 1);
    9796        }
    9897        for (i = 0; i < amb / 8; i++) {
    99                 /*
    100                  * The middle bits can be set byte by byte.
    101                  */
     98                /* The middle bits can be set byte by byte. */
    10299                bitmap->map[aligned_start / 8 + i] = ALL_ONES;
    103100        }
    104101        if (tab) {
    105                 /*
    106                  * Make sure to set any trailing aligned bits.
    107                  */
     102                /* Make sure to set any trailing aligned bits. */
    108103                bitmap->map[aligned_start / 8 + i] |= (1 << tab) - 1;
    109104        }
     
    113108/** Clear range of bits.
    114109 *
    115  * @param bitmap Bitmap structure.
    116  * @param start Starting bit.
    117  * @param bits Number of bits to clear.
     110 * @param bitmap        Bitmap structure.
     111 * @param start         Starting bit.
     112 * @param bits          Number of bits to clear.
    118113 */
    119114void bitmap_clear_range(bitmap_t *bitmap, size_t start, size_t bits)
     
    121116        size_t i = 0;
    122117        size_t aligned_start;
    123         size_t lub;             /* leading unaligned bits */
    124         size_t amb;             /* aligned middle bits */
    125         size_t tab;             /* trailing aligned bits */
     118        size_t lub;     /* leading unaligned bits */
     119        size_t amb;     /* aligned middle bits */
     120        size_t tab;     /* trailing aligned bits */
    126121       
    127122        ASSERT(start + bits <= bitmap->bits);
     
    132127        tab = amb % 8;
    133128
    134         if ( start + bits < aligned_start )
    135         {
    136             /*
    137             * Set bits in the middle of byte
    138             */
    139             bitmap->map[start / 8] &= ~(((1 << lub)-1) << (start&7));
    140             return;
     129        if (!bits)
     130                return;
     131
     132        if (start + bits < aligned_start) {
     133                /* Set bits in the middle of byte */
     134                bitmap->map[start / 8] &= ~(((1 << lub) - 1) << (start & 7));
     135                return;
    141136        }
    142137
    143 
    144138        if (lub) {
    145                 /*
    146                  * Make sure to clear any leading unaligned bits.
    147                  */
     139                /* Make sure to clear any leading unaligned bits. */
    148140                bitmap->map[start / 8] &= (1 << (8 - lub)) - 1;
    149141        }
    150142        for (i = 0; i < amb / 8; i++) {
    151                 /*
    152                  * The middle bits can be cleared byte by byte.
    153                  */
     143                /* The middle bits can be cleared byte by byte. */
    154144                bitmap->map[aligned_start / 8 + i] = ALL_ZEROES;
    155145        }
    156146        if (tab) {
    157                 /*
    158                  * Make sure to clear any trailing aligned bits.
    159                  */
     147                /* Make sure to clear any trailing aligned bits. */
    160148                bitmap->map[aligned_start / 8 + i] &= ~((1 << tab) - 1);
    161149        }
     
    165153/** Copy portion of one bitmap into another bitmap.
    166154 *
    167  * @param dst Destination bitmap.
    168  * @param src Source bitmap.
    169  * @param bits Number of bits to copy.
     155 * @param dst           Destination bitmap.
     156 * @param src           Source bitmap.
     157 * @param bits          Number of bits to copy.
    170158 */
    171159void bitmap_copy(bitmap_t *dst, bitmap_t *src, size_t bits)
  • tools/toolchain.sh

    r982e3d8 r8e189ef  
    6262        echo " ia32       IA-32 (x86, i386)"
    6363        echo " ia64       IA-64 (Itanium)"
    64         echo " mips32     MIPS little-endian"
    65         echo " mips32eb   MIPS big-endian"
     64        echo " mips32     MIPS little-endian 32b"
     65        echo " mips32eb   MIPS big-endian 32b"
     66        echo " mips64     MIPS little-endian 64b"
    6667        echo " ppc32      32-bit PowerPC"
    6768        echo " ppc64      64-bit PowerPC"
     
    303304                build_target "mips32eb" "mips-linux-gnu"
    304305                ;;
     306        "mips64")
     307                build_target "mips64" "mips64el-linux-gnu"
     308                ;;
    305309        "ppc32")
    306310                build_target "ppc32" "ppc-linux-gnu"
     
    320324                build_target "mips32" "mipsel-linux-gnu"
    321325                build_target "mips32eb" "mips-linux-gnu"
     326                build_target "mips64" "mips64el-linux-gnu"
    322327                build_target "ppc32" "ppc-linux-gnu"
    323328                build_target "ppc64" "ppc64-linux-gnu"
  • uspace/app/bdsh/cmds/modules/help/help.c

    r982e3d8 r8e189ef  
    4545extern const char *progname;
    4646
    47 #define HELP_IS_MODULE   1
    48 #define HELP_IS_BUILTIN  0
    49 #define HELP_IS_RUBBISH  -1
     47#define HELP_IS_COMMANDS        2
     48#define HELP_IS_MODULE          1
     49#define HELP_IS_BUILTIN         0
     50#define HELP_IS_RUBBISH         -1
    5051
    5152volatile int mod_switch = -1;
     
    5556{
    5657        int rc = HELP_IS_RUBBISH;
     58
     59        if (str_cmp(cmd, "commands") == 0)
     60                return HELP_IS_COMMANDS;
    5761
    5862        rc = is_builtin(cmd);
     
    9094}
    9195
    92 int cmd_help(char *argv[])
     96static void help_commands(void)
    9397{
     98        builtin_t *cmd;
    9499        module_t *mod;
    95         builtin_t *cmd;
    96         unsigned int i = 0;
    97         int rc = 0;
    98         int argc;
    99         int level = HELP_SHORT;
     100        unsigned int i;
    100101
    101         argc = cli_count_args(argv);
    102 
    103         if (argc > 3) {
    104                 printf("\nToo many arguments to `%s', try:\n", cmdname);
    105                 help_cmd_help(HELP_SHORT);
    106                 return CMD_FAILURE;
    107         }
    108 
    109         if (argc == 3) {
    110                 if (!str_cmp("extended", argv[2]))
    111                         level = HELP_LONG;
    112                 else
    113                         level = HELP_SHORT;
    114         }
    115 
    116         if (argc > 1) {
    117                 rc = is_mod_or_builtin(argv[1]);
    118                 switch (rc) {
    119                 case HELP_IS_RUBBISH:
    120                         printf("Invalid command %s\n", argv[1]);
    121                         return CMD_FAILURE;
    122                 case HELP_IS_MODULE:
    123                         help_module(mod_switch, level);
    124                         return CMD_SUCCESS;
    125                 case HELP_IS_BUILTIN:
    126                         help_builtin(mod_switch, level);
    127                         return CMD_SUCCESS;
    128                 }
    129         }
    130 
    131         printf("\n  Available commands are:\n");
     102        printf("\n  Bdsh built-in commands:\n");
    132103        printf("  ------------------------------------------------------------\n");
    133104
     
    154125        printf("\n  Try %s %s for more information on how `%s' works.\n\n",
    155126                cmdname, cmdname, cmdname);
     127}
     128
     129/** Display survival tips. ('help' without arguments) */
     130static void help_survival(void)
     131{
     132        printf("Don't panic!\n\n");
     133
     134        printf("This is Bdsh, the Brain dead shell, currently "
     135            "the primary user interface to HelenOS. Bdsh allows you to enter "
     136            "commands and supports history (Up, Down arrow keys), "
     137            "line editing (Left Arrow, Right Arrow, Home, End, Backspace), "
     138            "selection (Shift + movement keys), copy and paste (Ctrl-C, "
     139            "Ctrl-V), similar to common desktop environments.\n\n");
     140
     141        printf("The most basic filesystem commands are Bdsh builtins. Type "
     142            "'help commands' [Enter] to see the list of Bdsh builtin commands. "
     143            "Other commands are external executables located in the /app and "
     144            "/srv directories. Type 'ls /app' [Enter] and 'ls /srv' [Enter] "
     145            "to see their list. You can execute an external command simply "
     146            "by entering its name (e.g. type 'tetris' [Enter]).\n\n");
     147
     148        printf("HelenOS has virtual consoles (VCs). You can switch between "
     149            "these using the F1-F11 keys.\n\n");
     150
     151        printf("This is but a small glimpse of what you can do with HelenOS. "
     152            "To learn more please point your browser to the HelenOS User's "
     153            "Guide: http://trac.helenos.org/trac.fcgi/wiki/UsersGuide\n\n");
     154}
     155
     156int cmd_help(char *argv[])
     157{
     158        int rc = 0;
     159        int argc;
     160        int level = HELP_SHORT;
     161
     162        argc = cli_count_args(argv);
     163
     164        if (argc > 3) {
     165                printf("\nToo many arguments to `%s', try:\n", cmdname);
     166                help_cmd_help(HELP_SHORT);
     167                return CMD_FAILURE;
     168        }
     169
     170        if (argc == 3) {
     171                if (!str_cmp("extended", argv[2]))
     172                        level = HELP_LONG;
     173                else
     174                        level = HELP_SHORT;
     175        }
     176
     177        if (argc > 1) {
     178                rc = is_mod_or_builtin(argv[1]);
     179                switch (rc) {
     180                case HELP_IS_RUBBISH:
     181                        printf("Invalid topic %s\n", argv[1]);
     182                        return CMD_FAILURE;
     183                case HELP_IS_COMMANDS:
     184                        help_commands();
     185                        return CMD_SUCCESS;
     186                case HELP_IS_MODULE:
     187                        help_module(mod_switch, level);
     188                        return CMD_SUCCESS;
     189                case HELP_IS_BUILTIN:
     190                        help_builtin(mod_switch, level);
     191                        return CMD_SUCCESS;
     192                }
     193        }
     194
     195        help_survival();
    156196
    157197        return CMD_SUCCESS;
  • uspace/app/bdsh/scli.c

    r982e3d8 r8e189ef  
    8989                exit(EXIT_FAILURE);
    9090
    91         printf("Welcome to %s - %s\nType `help' at any time for usage information.\n",
    92                 progname, PACKAGE_STRING);
    93 
    9491        while (!cli_quit) {
    9592                get_input(&usr);
  • uspace/app/getterm/Makefile

    r982e3d8 r8e189ef  
    3434SOURCES = \
    3535        getterm.c \
    36         version.c
     36        version.c \
     37        welcome.c
    3738
    3839include $(USPACE_PREFIX)/Makefile.common
  • uspace/app/getterm/getterm.c

    r982e3d8 r8e189ef  
    4343#include <errno.h>
    4444#include "version.h"
     45#include "welcome.h"
    4546
    4647#define APP_NAME  "getterm"
     
    4849static void usage(void)
    4950{
    50         printf("Usage: %s <terminal> <path>\n", APP_NAME);
     51        printf("Usage: %s <terminal> [-w] <command> [<arguments...>]\n", APP_NAME);
    5152}
    5253
     
    7374}
    7475
    75 static task_id_t spawn(const char *fname)
    76 {
    77         task_id_t id;
    78         int rc;
    79        
    80         rc = task_spawnl(&id, fname, fname, NULL);
    81         if (rc != EOK) {
    82                 printf("%s: Error spawning %s (%s)\n", APP_NAME, fname,
    83                     str_error(rc));
    84                 return 0;
    85         }
    86        
    87         return id;
    88 }
    89 
    9076int main(int argc, char *argv[])
    9177{
    92         if (argc < 3) {
     78        int rc;
     79        task_exit_t texit;
     80        int retval;
     81        task_id_t id;
     82        char *fname, *term;
     83        char **cmd_args;
     84        bool print_wmsg;
     85
     86        ++argv; --argc;
     87        if (argc < 1) {
    9388                usage();
    9489                return -1;
    9590        }
     91
     92        if (str_cmp(*argv, "-w") == 0) {
     93                print_wmsg = true;
     94                ++argv; --argc;
     95        } else {
     96                print_wmsg = false;
     97        }
     98
     99        if (argc < 2) {
     100                usage();
     101                return -1;
     102        }
     103
     104        term = *argv++;
     105        fname = *argv;
     106        cmd_args = argv;
    96107       
    97         reopen(&stdin, 0, argv[1], O_RDONLY, "r");
    98         reopen(&stdout, 1, argv[1], O_WRONLY, "w");
    99         reopen(&stderr, 2, argv[1], O_WRONLY, "w");
     108        reopen(&stdin, 0, term, O_RDONLY, "r");
     109        reopen(&stdout, 1, term, O_WRONLY, "w");
     110        reopen(&stderr, 2, term, O_WRONLY, "w");
    100111       
    101112        /*
     
    114125                return -4;
    115126       
    116         version_print(argv[1]);
    117         task_id_t id = spawn(argv[2]);
    118        
    119         if (id != 0) {
    120                 task_exit_t texit;
    121                 int retval;
    122                 task_wait(id, &texit, &retval);
    123                
    124                 return 0;
     127        version_print(term);
     128        if (print_wmsg)
     129                welcome_msg_print();
     130
     131        rc = task_spawnv(&id, fname, (const char * const *) cmd_args);
     132        if (rc != EOK) {
     133                printf("%s: Error spawning %s (%s)\n", APP_NAME, fname,
     134                    str_error(rc));
     135                return -5;
    125136        }
    126        
    127         return -5;
     137
     138        rc = task_wait(id, &texit, &retval);
     139        if (rc != EOK) {
     140                printf("%s: Error waiting for %s (%s)\n", APP_NAME, fname,
     141                    str_error(rc));
     142                return -6;
     143        }
     144
     145        return 0;
    128146}
    129147
  • uspace/app/getterm/version.c

    r982e3d8 r8e189ef  
    6161        printf("HelenOS release %s (%s)%s%s\n", release, name, revision, timestamp);
    6262        printf("Running on %s (%s)\n", arch, term);
    63         printf("Copyright (c) 2001-2009 HelenOS project\n\n");
     63        printf("Copyright (c) 2001-2010 HelenOS project\n\n");
    6464}
    6565
  • uspace/app/init/init.c

    r982e3d8 r8e189ef  
    200200}
    201201
    202 static void getterm(const char *dev, const char *app)
     202static void getterm(const char *dev, const char *app, bool wmsg)
    203203{
    204204        char term[DEVMAP_NAME_MAXLEN];
     
    218218        }
    219219       
    220         rc = task_spawnl(NULL, APP_GETTERM, APP_GETTERM, term, app, NULL);
    221         if (rc != EOK) {
    222                 printf("%s: Error spawning %s %s %s (%s)\n", NAME,
    223                     APP_GETTERM, term, app, str_error(rc));
     220        if (wmsg) {
     221                rc = task_spawnl(NULL, APP_GETTERM, APP_GETTERM, "-w", term,
     222                    app, NULL);
     223                if (rc != EOK) {
     224                        printf("%s: Error spawning %s -w %s %s (%s)\n", NAME,
     225                            APP_GETTERM, term, app, str_error(rc));
     226                }
     227        } else {
     228                rc = task_spawnl(NULL, APP_GETTERM, APP_GETTERM, term, app,
     229                    NULL);
     230                if (rc != EOK) {
     231                        printf("%s: Error spawning %s %s %s (%s)\n", NAME,
     232                            APP_GETTERM, term, app, str_error(rc));
     233                }
    224234        }
    225235}
     
    295305#endif
    296306       
    297         getterm("term/vc0", "/app/bdsh");
    298         getterm("term/vc1", "/app/bdsh");
    299         getterm("term/vc2", "/app/bdsh");
    300         getterm("term/vc3", "/app/bdsh");
    301         getterm("term/vc4", "/app/bdsh");
    302         getterm("term/vc5", "/app/bdsh");
    303         getterm("term/vc6", "/app/klog");
     307        getterm("term/vc0", "/app/bdsh", true);
     308        getterm("term/vc1", "/app/bdsh", false);
     309        getterm("term/vc2", "/app/bdsh", false);
     310        getterm("term/vc3", "/app/bdsh", false);
     311        getterm("term/vc4", "/app/bdsh", false);
     312        getterm("term/vc5", "/app/bdsh", false);
     313        getterm("term/vc6", "/app/klog", false);
    304314       
    305315        return 0;
  • uspace/app/nettest1/nettest1.c

    r982e3d8 r8e189ef  
    287287int main(int argc, char *argv[])
    288288{
    289 
    290         socklen_t max_length;
    291         uint8_t *address_data[sizeof(struct sockaddr_in6)];
    292         struct sockaddr_in *address_in;
    293         struct sockaddr_in6 *address_in6;
     289        struct sockaddr_in address_in;
     290        struct sockaddr_in6 address_in6;
    294291        uint8_t *address_start;
    295292
     
    300297
    301298        int rc;
    302 
    303         max_length = sizeof(address_data);
    304         address = (struct sockaddr *) address_data;
    305         address_in = (struct sockaddr_in *) address;
    306         address_in6 = (struct sockaddr_in6 *) address;
    307299
    308300        sockets = 10;
     
    334326
    335327        /* Prepare the address buffer */
    336         bzero(address_data, max_length);
    337328
    338329        switch (family) {
    339330        case PF_INET:
    340                 address_in->sin_family = AF_INET;
    341                 address_in->sin_port = htons(port);
    342                 address_start = (uint8_t *) &address_in->sin_addr.s_addr;
    343                 addrlen = sizeof(struct sockaddr_in);
     331                address_in.sin_family = AF_INET;
     332                address_in.sin_port = htons(port);
     333                address = (struct sockaddr *) &address_in;
     334                addrlen = sizeof(address_in);
     335                address_start = (uint8_t *) &address_in.sin_addr.s_addr;
    344336                break;
    345337        case PF_INET6:
    346                 address_in6->sin6_family = AF_INET6;
    347                 address_in6->sin6_port = htons(port);
    348                 address_start = (uint8_t *) &address_in6->sin6_addr.s6_addr;
    349                 addrlen = sizeof(struct sockaddr_in6);
     338                address_in6.sin6_family = AF_INET6;
     339                address_in6.sin6_port = htons(port);
     340                address = (struct sockaddr *) &address_in6;
     341                addrlen = sizeof(address_in6);
     342                address_start = (uint8_t *) &address_in6.sin6_addr.s6_addr;
    350343                break;
    351344        default:
  • uspace/app/nettest2/nettest2.c

    r982e3d8 r8e189ef  
    223223int main(int argc, char *argv[])
    224224{
    225         socklen_t max_length;
    226         uint8_t address_data[sizeof(struct sockaddr_in6)];
    227225        struct sockaddr *address;
    228         struct sockaddr_in *address_in;
    229         struct sockaddr_in6 *address_in6;
     226        struct sockaddr_in address_in;
     227        struct sockaddr_in6 address_in6;
    230228        socklen_t addrlen;
    231229        uint8_t *address_start;
     
    247245        port = 7;
    248246
    249         max_length = sizeof(address_data);
    250         address = (struct sockaddr *) address_data;
    251         address_in = (struct sockaddr_in *) address;
    252         address_in6 = (struct sockaddr_in6 *) address;
    253 
    254247        /*
    255248         * Parse the command line arguments.
     
    279272
    280273        /* Prepare the address buffer */
    281         bzero(address_data, max_length);
    282274
    283275        switch (family) {
    284276        case PF_INET:
    285                 address_in->sin_family = AF_INET;
    286                 address_in->sin_port = htons(port);
    287                 address_start = (uint8_t *) &address_in->sin_addr.s_addr;
    288                 addrlen = sizeof(struct sockaddr_in);
     277                address_in.sin_family = AF_INET;
     278                address_in.sin_port = htons(port);
     279                address = (struct sockaddr *) &address_in;
     280                addrlen = sizeof(address_in);
     281                address_start = (uint8_t *) &address_in.sin_addr.s_addr;
    289282                break;
    290283        case PF_INET6:
    291                 address_in6->sin6_family = AF_INET6;
    292                 address_in6->sin6_port = htons(port);
    293                 address_start = (uint8_t *) &address_in6->sin6_addr.s6_addr;
    294                 addrlen = sizeof(struct sockaddr_in6);
     284                address_in6.sin6_family = AF_INET6;
     285                address_in6.sin6_port = htons(port);
     286                address = (struct sockaddr *) &address_in6;
     287                addrlen = sizeof(address_in6);
     288                address_start = (uint8_t *) &address_in6.sin6_addr.s6_addr;
    295289                break;
    296290        default:
  • uspace/lib/c/include/stdio.h

    r982e3d8 r8e189ef  
    4646#define BUFSIZ  4096
    4747
    48 #define DEBUG(fmt, ...)se\
     48#define DEBUG(fmt, ...) \
    4949        { \
    5050                char _buf[256]; \
  • uspace/srv/hw/netif/dp8390/dp8390.h

    r982e3d8 r8e189ef  
    4343/** Input/output size.
    4444 */
    45 #define DP8390_IO_SIZE  0x01f
     45#define DP8390_IO_SIZE  0x020
    4646
    4747/*
  • uspace/srv/net/il/arp/arp.c

    r982e3d8 r8e189ef  
    125125}
    126126
    127 static int
    128 arp_clear_address_req(int arp_phone, device_id_t device_id, services_t protocol,
    129     measured_string_ref address)
     127static int arp_clear_address_req(int arp_phone, device_id_t device_id,
     128    services_t protocol, measured_string_ref address)
    130129{
    131130        arp_device_ref device;
     
    175174 * @returns             ENOMEM if there is not enough memory left.
    176175 */
    177 static int
    178 arp_proto_create(arp_proto_ref *proto, services_t service,
     176static int arp_proto_create(arp_proto_ref *proto, services_t service,
    179177    measured_string_ref address)
    180178{
     
    214212 *                      measured_strings_return() function.
    215213 */
    216 static int
    217 arp_device_message(device_id_t device_id, services_t service,
     214static int arp_device_message(device_id_t device_id, services_t service,
    218215    services_t protocol, measured_string_ref address)
    219216{
     
    225222
    226223        fibril_rwlock_write_lock(&arp_globals.lock);
    227         // an existing device?
     224
     225        /* An existing device? */
    228226        device = arp_cache_find(&arp_globals.cache, device_id);
     227
    229228        if (device) {
    230229                if (device->service != service) {
     
    260259                        return ENOENT;
    261260               
    262                 // create a new device
     261                /* Create a new device */
    263262                device = (arp_device_ref) malloc(sizeof(arp_device_t));
    264263                if (!device) {
     
    289288                device->service = service;
    290289               
    291                 // bind the new one
     290                /* Bind the new one */
    292291                device->phone = nil_bind_service(device->service,
    293292                    (ipcarg_t) device->device_id, SERVICE_ARP,
     
    300299                }
    301300               
    302                 // get packet dimensions
     301                /* Get packet dimensions */
    303302                rc = nil_packet_size_req(device->phone, device_id,
    304303                    &device->packet_dimension);
     
    310309                }
    311310               
    312                 // get hardware address
     311                /* Get hardware address */
    313312                rc = nil_get_addr_req(device->phone, device_id, &device->addr,
    314313                    &device->addr_data);
     
    320319                }
    321320               
    322                 // get broadcast address
     321                /* Get broadcast address */
    323322                rc = nil_get_broadcast_addr_req(device->phone, device_id,
    324323                    &device->broadcast_addr, &device->broadcast_data);
     
    455454        hw_source = arp_addr_find(&proto->addresses, (char *) src_proto,
    456455            CONVERT_SIZE(uint8_t, char, header->protocol_length));
    457         // exists?
     456        /* Exists? */
    458457        if (hw_source) {
    459458                if (hw_source->length != CONVERT_SIZE(uint8_t, char,
     
    463462                memcpy(hw_source->value, src_hw, hw_source->length);
    464463        }
    465         // is my protocol address?
     464        /* Is my protocol address? */
    466465        if (proto->addr->length != CONVERT_SIZE(uint8_t, char,
    467466            header->protocol_length)) {
     
    470469        if (!str_lcmp(proto->addr->value, (char *) des_proto,
    471470            proto->addr->length)) {
    472                 // not already upadted?
     471                /* Not already updated? */
    473472                if (!hw_source) {
    474473                        hw_source = measured_string_create_bulk((char *) src_hw,
     
    550549                return addr;
    551550
    552         // ARP packet content size = header + (address + translation) * 2
     551        /* ARP packet content size = header + (address + translation) * 2 */
    553552        length = 8 + 2 * (CONVERT_SIZE(char, uint8_t, proto->addr->length) +
    554553            CONVERT_SIZE(char, uint8_t, device->addr->length));
     
    674673       
    675674        case NET_IL_DEVICE_STATE:
    676                 // do nothing - keep the cache
     675                /* Do nothing - keep the cache */
    677676                return EOK;
    678677       
  • uspace/srv/net/il/arp/arp_module.c

    r982e3d8 r8e189ef  
    5757extern arp_globals_t arp_globals;
    5858
    59 int
    60 il_module_message_standalone(ipc_callid_t callid, ipc_call_t *call,
     59int il_module_message_standalone(ipc_callid_t callid, ipc_call_t *call,
    6160    ipc_call_t *answer, int *answer_count)
    6261{
  • uspace/srv/net/net/net.c

    r982e3d8 r8e189ef  
    275275        measured_strings_initialize(&net_globals.configuration);
    276276       
    277         // TODO: dynamic configuration
     277        /* TODO: dynamic configuration */
    278278        rc = read_configuration();
    279279        if (rc != EOK)
     
    347347 *
    348348 * The network interface configuration is searched first.
    349  &
     349 *
    350350 * @param[in]  netif_conf    The network interface configuration setting.
    351351 * @param[out] configuration The found configured values.
  • uspace/srv/net/netif/lo/lo.c

    r982e3d8 r8e189ef  
    6464netif_globals_t netif_globals;
    6565
    66 int
    67 netif_specific_message(ipc_callid_t callid, ipc_call_t *call,
     66int netif_specific_message(ipc_callid_t callid, ipc_call_t *call,
    6867    ipc_call_t *answer, int *answer_count)
    6968{
     
    7574        if (!address)
    7675                return EBADMEM;
     76
    7777        address->value = str_dup(DEFAULT_ADDR);
    7878        address->length = DEFAULT_ADDR_LEN;
     79
    7980        return EOK;
    8081}
     
    8788        if (!stats)
    8889                return EBADMEM;
     90
    8991        rc = find_device(device_id, &device);
    9092        if (rc != EOK)
    9193                return rc;
     94
    9295        memcpy(stats, (device_stats_ref) device->specific,
    9396            sizeof(device_stats_t));
     97
    9498        return EOK;
    9599}
     
    134138        if (!*device)
    135139                return ENOMEM;
     140
    136141        (*device)->specific = (device_stats_t *) malloc(sizeof(device_stats_t));
    137142        if (!(*device)->specific) {
     
    139144                return ENOMEM;
    140145        }
     146
    141147        null_device_stats((device_stats_ref) (*device)->specific);
    142148        (*device)->device_id = device_id;
     
    145151        index = netif_device_map_add(&netif_globals.device_map,
    146152            (*device)->device_id, *device);
     153
    147154        if (index < 0) {
    148155                free(*device);
     
    167174        int rc;
    168175
    169         // create a new device
     176        /* Create a new device */
    170177        rc = create(device_id, &device);
    171178        if (rc != EOK)
    172179                return rc;
    173         // print the settings
     180
     181        /* Print the settings */
    174182        printf("%s: Device created (id: %d)\n", NAME, device->device_id);
     183
    175184        return EOK;
    176185}
     
    187196        if (rc != EOK)
    188197                return EOK;
     198
    189199        if (device->state != NETIF_ACTIVE) {
    190200                netif_pq_release(packet_get_id(packet));
    191201                return EFORWARD;
    192202        }
     203
    193204        next = packet;
    194205        do {
     
    200211                next = pq_next(next);
    201212        } while(next);
     213
    202214        phone = device->nil_phone;
    203215        fibril_rwlock_write_unlock(&netif_globals.lock);
  • uspace/srv/net/nil/eth/eth.c

    r982e3d8 r8e189ef  
    204204        fibril_rwlock_write_lock(&eth_globals.protos_lock);
    205205        eth_globals.net_phone = net_phone;
     206
    206207        eth_globals.broadcast_addr =
    207208            measured_string_create_bulk("\xFF\xFF\xFF\xFF\xFF\xFF",
     
    211212                goto out;
    212213        }
     214
    213215        rc = eth_devices_initialize(&eth_globals.devices);
    214216        if (rc != EOK) {
     
    216218                goto out;
    217219        }
     220
    218221        rc = eth_protos_initialize(&eth_globals.protos);
    219222        if (rc != EOK) {
     
    280283 *                      netif_get_addr_req() function.
    281284 */
    282 static int
    283 eth_device_message(device_id_t device_id, services_t service, size_t mtu)
     285static int eth_device_message(device_id_t device_id, services_t service,
     286    size_t mtu)
    284287{
    285288        eth_device_ref device;
     
    302305
    303306        fibril_rwlock_write_lock(&eth_globals.devices_lock);
    304         // an existing device?
     307        /* An existing device? */
    305308        device = eth_devices_find(&eth_globals.devices, device_id);
    306309        if (device) {
     
    311314                }
    312315               
    313                 // update mtu
     316                /* Update mtu */
    314317                if ((mtu > 0) && (mtu <= ETH_MAX_TAGGED_CONTENT(device->flags)))
    315318                        device->mtu = mtu;
     
    321324                fibril_rwlock_write_unlock(&eth_globals.devices_lock);
    322325               
    323                 // notify all upper layer modules
     326                /* Notify all upper layer modules */
    324327                fibril_rwlock_read_lock(&eth_globals.protos_lock);
    325328                for (index = 0; index < eth_protos_count(&eth_globals.protos);
     
    333336                        }
    334337                }
     338
    335339                fibril_rwlock_read_unlock(&eth_globals.protos_lock);
    336340                return EOK;
    337341        }
    338342       
    339         // create a new device
     343        /* Create a new device */
    340344        device = (eth_device_ref) malloc(sizeof(eth_device_t));
    341345        if (!device)
     
    358362                return rc;
    359363        }
     364
    360365        if (configuration) {
    361366                if (!str_lcmp(configuration[0].value, "DIX",
     
    378383        }
    379384       
    380         // bind the device driver
     385        /* Bind the device driver */
    381386        device->phone = netif_bind_service(device->service, device->device_id,
    382387            SERVICE_ETHERNET, eth_receiver);
     
    387392        }
    388393       
    389         // get hardware address
     394        /* Get hardware address */
    390395        rc = netif_get_addr_req(device->phone, device->device_id, &device->addr,
    391396            &device->addr_data);
     
    396401        }
    397402       
    398         // add to the cache
     403        /* Add to the cache */
    399404        index = eth_devices_add(&eth_globals.devices, device->device_id,
    400405            device);
     
    453458       
    454459        if (type >= ETH_MIN_PROTO) {
    455                 // DIX Ethernet
     460                /* DIX Ethernet */
    456461                prefix = sizeof(eth_header_t);
    457462                suffix = 0;
     
    459464                length -= sizeof(eth_fcs_t);
    460465        } else if(type <= ETH_MAX_CONTENT) {
    461                 // translate "LSAP" values
     466                /* Translate "LSAP" values */
    462467                if ((header->lsap.dsap == ETH_LSAP_GLSAP) &&
    463468                    (header->lsap.ssap == ETH_LSAP_GLSAP)) {
    464                         // raw packet
    465                         // discard
     469                        /* Raw packet -- discard */
    466470                        return NULL;
    467471                } else if((header->lsap.dsap == ETH_LSAP_SNAP) &&
    468472                    (header->lsap.ssap == ETH_LSAP_SNAP)) {
    469                         // IEEE 802.3 + 802.2 + LSAP + SNAP
    470                         // organization code not supported
     473                        /*
     474                         * IEEE 802.3 + 802.2 + LSAP + SNAP
     475                         * organization code not supported
     476                         */
    471477                        type = ntohs(header->snap.ethertype);
    472478                        prefix = sizeof(eth_header_t) +
     
    474480                            sizeof(eth_header_snap_t);
    475481                } else {
    476                         // IEEE 802.3 + 802.2 LSAP
     482                        /* IEEE 802.3 + 802.2 LSAP */
    477483                        type = lsap_map(header->lsap.dsap);
    478484                        prefix = sizeof(eth_header_t) +
    479485                            sizeof(eth_header_lsap_t);
    480486                }
     487
    481488                suffix = (type < ETH_MIN_CONTENT) ? ETH_MIN_CONTENT - type : 0U;
    482489                fcs = (eth_fcs_ref) data + prefix + type + suffix;
     
    484491                length = prefix + type + suffix;
    485492        } else {
    486                 // invalid length/type, should not occurr
     493                /* Invalid length/type, should not occur */
    487494                return NULL;
    488495        }
     
    506513}
    507514
    508 int
    509 nil_received_msg_local(int nil_phone, device_id_t device_id, packet_t packet,
    510     services_t target)
     515int nil_received_msg_local(int nil_phone, device_id_t device_id,
     516    packet_t packet, services_t target)
    511517{
    512518        eth_proto_ref proto;
     
    521527                return ENOENT;
    522528        }
     529
    523530        flags = device->flags;
    524531        fibril_rwlock_read_unlock(&eth_globals.devices_lock);
     
    538545                packet = next;
    539546        } while(packet);
     547
    540548        fibril_rwlock_read_unlock(&eth_globals.protos_lock);
    541        
    542549        return EOK;
    543550}
     
    554561 * @returns             ENOENT if there is no such device.
    555562 */
    556 static int
    557 eth_packet_space_message(device_id_t device_id, size_t *addr_len,
     563static int eth_packet_space_message(device_id_t device_id, size_t *addr_len,
    558564    size_t *prefix, size_t *content, size_t *suffix)
    559565{
     
    569575                return ENOENT;
    570576        }
     577
    571578        *content = device->mtu;
    572579        fibril_rwlock_read_unlock(&eth_globals.devices_lock);
     
    575582        *prefix = ETH_PREFIX;
    576583        *suffix = ETH_MIN_CONTENT + ETH_SUFFIX;
     584
    577585        return EOK;
    578586}
     
    587595 * @returns             ENOENT if there no such device.
    588596 */
    589 static int
    590 eth_addr_message(device_id_t device_id, eth_addr_type_t type,
     597static int eth_addr_message(device_id_t device_id, eth_addr_type_t type,
    591598    measured_string_ref *address)
    592599{
     
    644651                        return ENOMEM;
    645652                }
     653
    646654                proto->service = service;
    647655                proto->protocol = protocol;
    648656                proto->phone = phone;
     657
    649658                index = eth_protos_add(&eth_globals.protos, protocol, proto);
    650659                if (index < 0) {
     
    705714                if (!padding)
    706715                        return ENOMEM;
     716
    707717                bzero(padding, ETH_MIN_TAGGED_CONTENT(flags) - length);
    708718        }
     
    782792 * @returns             EINVAL if the service parameter is not known.
    783793 */
    784 static int
    785 eth_send_message(device_id_t device_id, packet_t packet, services_t sender)
     794static int eth_send_message(device_id_t device_id, packet_t packet,
     795    services_t sender)
    786796{
    787797        eth_device_ref device;
     
    804814        }
    805815       
    806         // process packet queue
     816        /* Process packet queue */
    807817        next = packet;
    808818        do {
     
    810820                    (uint8_t *) device->addr->value, ethertype, device->mtu);
    811821                if (rc != EOK) {
    812                         // release invalid packet
     822                        /* Release invalid packet */
    813823                        tmp = pq_detach(next);
    814824                        if (next == packet)
     
    822832        } while(next);
    823833       
    824         // send packet queue
     834        /* Send packet queue */
    825835        if (packet) {
    826836                netif_send_msg(device->phone, device_id, packet,
    827837                    SERVICE_ETHERNET);
    828838        }
     839
    829840        fibril_rwlock_read_unlock(&eth_globals.devices_lock);
    830        
    831841        return EOK;
    832842}
    833843
    834 int
    835 nil_message_standalone(const char *name, ipc_callid_t callid, ipc_call_t *call,
    836     ipc_call_t *answer, int *answer_count)
     844int nil_message_standalone(const char *name, ipc_callid_t callid,
     845    ipc_call_t *call, ipc_call_t *answer, int *answer_count)
    837846{
    838847        measured_string_ref address;
     
    894903 * @param[in] iid       The initial message identifier.
    895904 * @param[in] icall     The initial message call structure.
    896  *
    897905 */
    898906static void nil_client_connection(ipc_callid_t iid, ipc_call_t *icall)
  • uspace/srv/net/nil/eth/eth_module.c

    r982e3d8 r8e189ef  
    7777}
    7878
    79 int
    80 nil_module_message_standalone(const char *name, ipc_callid_t callid,
     79int nil_module_message_standalone(const char *name, ipc_callid_t callid,
    8180    ipc_call_t *call, ipc_call_t *answer, int *answer_count)
    8281{
  • uspace/srv/net/nil/nildummy/nildummy.c

    r982e3d8 r8e189ef  
    150150 *                      netif_get_addr_req() function.
    151151 */
    152 static int
    153 nildummy_device_message(device_id_t device_id, services_t service, size_t mtu)
     152static int nildummy_device_message(device_id_t device_id, services_t service,
     153    size_t mtu)
    154154{
    155155        nildummy_device_ref device;
     
    159159        fibril_rwlock_write_lock(&nildummy_globals.devices_lock);
    160160
    161         // an existing device?
     161        /* An existing device? */
    162162        device = nildummy_devices_find(&nildummy_globals.devices, device_id);
    163163        if (device) {
     
    169169                }
    170170               
    171                 // update mtu
     171                /* Update MTU */
    172172                if (mtu > 0)
    173173                        device->mtu = mtu;
     
    179179                fibril_rwlock_write_unlock(&nildummy_globals.devices_lock);
    180180               
    181                 // notify the upper layer module
     181                /* Notify the upper layer module */
    182182                fibril_rwlock_read_lock(&nildummy_globals.protos_lock);
    183183                if (nildummy_globals.proto.phone) {
     
    191191        }
    192192       
    193         // create a new device
     193        /* Create a new device */
    194194        device = (nildummy_device_ref) malloc(sizeof(nildummy_device_t));
    195195        if (!device)
     
    203203                device->mtu = NET_DEFAULT_MTU;
    204204
    205         // bind the device driver
     205        /* Bind the device driver */
    206206        device->phone = netif_bind_service(device->service, device->device_id,
    207207            SERVICE_ETHERNET, nildummy_receiver);
     
    212212        }
    213213       
    214         // get hardware address
     214        /* Get hardware address */
    215215        rc = netif_get_addr_req(device->phone, device->device_id, &device->addr,
    216216            &device->addr_data);
     
    221221        }
    222222       
    223         // add to the cache
     223        /* Add to the cache */
    224224        index = nildummy_devices_add(&nildummy_globals.devices,
    225225            device->device_id, device);
     
    247247 *
    248248 */
    249 static int
    250 nildummy_addr_message(device_id_t device_id, measured_string_ref *address)
     249static int nildummy_addr_message(device_id_t device_id,
     250    measured_string_ref *address)
    251251{
    252252        nildummy_device_ref device;
     
    279279 *
    280280 */
    281 static int
    282 nildummy_packet_space_message(device_id_t device_id, size_t *addr_len,
     281static int nildummy_packet_space_message(device_id_t device_id, size_t *addr_len,
    283282    size_t *prefix, size_t *content, size_t *suffix)
    284283{
     
    294293                return ENOENT;
    295294        }
     295
    296296        *content = device->mtu;
    297297        fibril_rwlock_read_unlock(&nildummy_globals.devices_lock);
     
    303303}
    304304
    305 int
    306 nil_received_msg_local(int nil_phone, device_id_t device_id, packet_t packet,
    307     services_t target)
     305int nil_received_msg_local(int nil_phone, device_id_t device_id,
     306    packet_t packet, services_t target)
    308307{
    309308        packet_t next;
     
    355354 * @return              EINVAL if the service parameter is not known.
    356355 */
    357 static int
    358 nildummy_send_message(device_id_t device_id, packet_t packet, services_t sender)
     356static int nildummy_send_message(device_id_t device_id, packet_t packet,
     357    services_t sender)
    359358{
    360359        nildummy_device_ref device;
     
    366365                return ENOENT;
    367366        }
    368         // send packet queue
     367
     368        /* Send packet queue */
    369369        if (packet)
    370370                netif_send_msg(device->phone, device_id, packet,
     
    374374}
    375375
    376 int
    377 nil_message_standalone(const char *name, ipc_callid_t callid, ipc_call_t *call,
    378     ipc_call_t *answer, int *answer_count)
     376int nil_message_standalone(const char *name, ipc_callid_t callid,
     377    ipc_call_t *call, ipc_call_t *answer, int *answer_count)
    379378{
    380379        measured_string_ref address;
  • uspace/srv/net/nil/nildummy/nildummy_module.c

    r982e3d8 r8e189ef  
    7878}
    7979
    80 int
    81 nil_module_message_standalone(const char *name, ipc_callid_t callid,
     80int nil_module_message_standalone(const char *name, ipc_callid_t callid,
    8281    ipc_call_t *call, ipc_call_t *answer, int *answer_count)
    8382{
  • uspace/srv/net/tl/icmp/icmp.c

    r982e3d8 r8e189ef  
    155155 * @returns             EPERM if the error message is not allowed.
    156156 */
    157 static int
    158 icmp_send_packet(icmp_type_t type, icmp_code_t code, packet_t packet,
     157static int icmp_send_packet(icmp_type_t type, icmp_code_t code, packet_t packet,
    159158    icmp_header_ref header, services_t error, ip_ttl_t ttl, ip_tos_t tos,
    160159    int dont_fragment)
     
    162161        int rc;
    163162
    164         // do not send an error if disabled
     163        /* Do not send an error if disabled */
    165164        if (error && !icmp_globals.error_reporting)
    166165                return icmp_release_and_return(packet, EPERM);
     
    204203                return NULL;
    205204
    206         // truncate if longer than 64 bits (without the IP header)
     205        /* Truncate if longer than 64 bits (without the IP header) */
    207206        if ((total_length > header_length + ICMP_KEEP_LENGTH) &&
    208207            (packet_trim(packet, 0,
     
    244243 * @returns             EPARTY if there was an internal error.
    245244 */
    246 static int
    247 icmp_echo(icmp_param_t id, icmp_param_t sequence, size_t size,
     245static int icmp_echo(icmp_param_t id, icmp_param_t sequence, size_t size,
    248246    mseconds_t timeout, ip_ttl_t ttl, ip_tos_t tos, int dont_fragment,
    249247    const struct sockaddr * addr, socklen_t addrlen)
     
    262260
    263261        length = (size_t) addrlen;
    264         // TODO do not ask all the time
     262        /* TODO do not ask all the time */
    265263        rc = ip_packet_size_req(icmp_globals.ip_phone, -1,
    266264            &icmp_globals.packet_dimension);
     
    275273                return ENOMEM;
    276274
    277         // prepare the requesting packet
    278         // set the destination address
     275        /* Prepare the requesting packet, set the destination address. */
    279276        rc = packet_set_addr(packet, NULL, (const uint8_t *) addr, length);
    280277        if (rc != EOK)
    281278                return icmp_release_and_return(packet, rc);
    282279
    283         // allocate space in the packet
     280        /* Allocate space in the packet */
    284281        data = (uint8_t *) packet_suffix(packet, size);
    285282        if (!data)
    286283                return icmp_release_and_return(packet, ENOMEM);
    287284
    288         // fill the data
     285        /* Fill the data */
    289286        length = 0;
    290287        while (size > length + sizeof(ICMP_ECHO_TEXT)) {
     
    294291        memcpy(data + length, ICMP_ECHO_TEXT, size - length);
    295292
    296         // prefix the header
     293        /* Prefix the header */
    297294        header = PACKET_PREFIX(packet, icmp_header_t);
    298295        if (!header)
     
    303300        header->un.echo.sequence_number = sequence;
    304301
    305         // prepare the reply structure
     302        /* Prepare the reply structure */
    306303        reply = malloc(sizeof(*reply));
    307304        if (!reply)
     
    319316        }
    320317
    321         // unlock the globals so that we can wait for the reply
     318        /* Unlock the globals so that we can wait for the reply */
    322319        fibril_rwlock_write_unlock(&icmp_globals.lock);
    323320
    324         // send the request
     321        /* Send the request */
    325322        icmp_send_packet(ICMP_ECHO, 0, packet, header, 0, ttl, tos,
    326323            dont_fragment);
    327324
    328         // wait for the reply
    329         // timeout in microseconds
     325        /* Wait for the reply. Timeout in microseconds. */
    330326        rc = fibril_condvar_wait_timeout(&reply->condvar, &reply->mutex,
    331327            timeout * 1000);
     
    333329                rc = reply->result;
    334330
    335         // drop the reply mutex before locking the globals again
     331        /* Drop the reply mutex before locking the globals again */
    336332        fibril_mutex_unlock(&reply->mutex);
    337333        fibril_rwlock_write_lock(&icmp_globals.lock);
    338334
    339         // destroy the reply structure
     335        /* Destroy the reply structure */
    340336        icmp_replies_exclude_index(&icmp_globals.replies, index);
    341337
     
    343339}
    344340
    345 static int
    346 icmp_destination_unreachable_msg_local(int icmp_phone, icmp_code_t code,
    347     icmp_param_t mtu, packet_t packet)
     341static int icmp_destination_unreachable_msg_local(int icmp_phone,
     342    icmp_code_t code, icmp_param_t mtu, packet_t packet)
    348343{
    349344        icmp_header_ref header;
     
    372367}
    373368
    374 static int
    375 icmp_time_exceeded_msg_local(int icmp_phone, icmp_code_t code, packet_t packet)
     369static int icmp_time_exceeded_msg_local(int icmp_phone, icmp_code_t code,
     370    packet_t packet)
    376371{
    377372        icmp_header_ref header;
     
    385380}
    386381
    387 static int
    388 icmp_parameter_problem_msg_local(int icmp_phone, icmp_code_t code,
     382static int icmp_parameter_problem_msg_local(int icmp_phone, icmp_code_t code,
    389383    icmp_param_t pointer, packet_t packet)
    390384{
     
    449443        icmp_globals.echo_replying = NET_DEFAULT_ICMP_ECHO_REPLYING;
    450444
    451         // get configuration
     445        /* Get configuration */
    452446        configuration = &names[0];
    453447        rc = net_get_conf_req(icmp_globals.net_phone, &configuration, count,
     
    485479 * @param[in] code      The received reply message code.
    486480 */
    487 static void
    488 icmp_process_echo_reply(packet_t packet, icmp_header_ref header,
     481static void  icmp_process_echo_reply(packet_t packet, icmp_header_ref header,
    489482    icmp_type_t type, icmp_code_t code)
    490483{
     
    492485        icmp_reply_ref reply;
    493486
    494         // compute the reply key
     487        /* Compute the reply key */
    495488        reply_key = ICMP_GET_REPLY_KEY(header->un.echo.identifier,
    496489            header->un.echo.sequence_number);
    497490        pq_release_remote(icmp_globals.net_phone, packet_get_id(packet));
    498491
     492        /* Find the pending reply */
    499493        fibril_rwlock_write_lock(&icmp_globals.lock);
    500         // find the pending reply
    501494        reply = icmp_replies_find(&icmp_globals.replies, reply_key);
    502495        if (reply) {
     
    541534                break;
    542535        case SERVICE_ICMP:
    543                 // process error
     536                /* Process error */
    544537                result = icmp_client_process_packet(packet, &type, &code, NULL,
    545538                    NULL);
     
    547540                        return result;
    548541                length = (size_t) result;
    549                 // remove the error header
     542                /* Remove the error header */
    550543                rc = packet_trim(packet, length, 0);
    551544                if (rc != EOK)
     
    556549        }
    557550
    558         // get rid of the ip header
     551        /* Get rid of the IP header */
    559552        length = ip_client_header_length(packet);
    560553        rc = packet_trim(packet, length, 0);
     
    573566                return EINVAL;
    574567
    575         // get icmp header
     568        /* Get ICMP header */
    576569        header = (icmp_header_ref) data;
    577570
    578571        if (header->checksum) {
    579572                while (ICMP_CHECKSUM(header, length) != IP_CHECKSUM_ZERO) {
    580                         // set the original message type on error notification
    581                         // type swap observed in Qemu
     573                        /*
     574                         * Set the original message type on error notification.
     575                         * Type swap observed in Qemu.
     576                         */
    582577                        if (error) {
    583578                                switch (header->type) {
     
    606601                }
    607602               
    608                 // do not send a reply if disabled
     603                /* Do not send a reply if disabled */
    609604                if (icmp_globals.echo_replying) {
    610605                        addrlen = packet_get_addr(packet, &src, NULL);
    611606
    612                         // set both addresses to the source one (avoids the
    613                         // source address deletion before setting the
    614                         // destination one)
     607                        /*
     608                         * Set both addresses to the source one (avoids the
     609                         * source address deletion before setting the
     610                         * destination one).
     611                         */
    615612                        if ((addrlen > 0) && (packet_set_addr(packet, src, src,
    616613                            (size_t) addrlen) == EOK)) {
    617                                 // send the reply
     614                                /* Send the reply */
    618615                                icmp_send_packet(ICMP_ECHOREPLY, 0, packet,
    619616                                    header, 0, 0, 0, 0);
     
    661658 *                      icmp_process_packet() function.
    662659 */
    663 static int
    664 icmp_received_msg_local(device_id_t device_id, packet_t packet,
     660static int icmp_received_msg_local(device_id_t device_id, packet_t packet,
    665661    services_t receiver, services_t error)
    666662{
     
    746742                return EBADMEM;
    747743
    748         // from the last used one
     744        /* From the last used one */
    749745        index = icmp_globals.last_used_id;
    750746        do {
    751747                index++;
    752                 // til the range end
     748                /* til the range end */
    753749                if (index >= ICMP_FREE_IDS_END) {
    754                         // start from the range beginning
     750                        /* start from the range beginning */
    755751                        index = ICMP_FREE_IDS_START - 1;
    756752                        do {
    757753                                index++;
    758                                 // til the last used one
     754                                /* til the last used one */
    759755                                if (index >= icmp_globals.last_used_id) {
    760                                         // none found
     756                                        /* none found */
    761757                                        return ENOTCONN;
    762758                                }
     
    764760                            index) != NULL);
    765761
    766                         // found, break immediately
     762                        /* Found, break immediately */
    767763                        break;
    768764                }
     
    808804                return ENOMEM;
    809805
    810         // assign a new identifier
     806        /* Assign a new identifier */
    811807        fibril_rwlock_write_lock(&icmp_globals.lock);
    812808        rc = icmp_bind_free_id(echo_data);
     
    818814
    819815        while (keep_on_going) {
    820                 // answer the call
     816                /* Answer the call */
    821817                answer_call(callid, rc, &answer, answer_count);
    822818
    823                 // refresh data
     819                /* Refresh data */
    824820                refresh_answer(&answer, &answer_count);
    825821
    826                 // get the next call
     822                /* Get the next call */
    827823                callid = async_get_call(&call);
    828824
    829                 // process the call
     825                /* Process the call */
    830826                switch (IPC_GET_METHOD(call)) {
    831827                case IPC_M_PHONE_HUNGUP:
     
    876872        }
    877873
    878         // release the identifier
     874        /* Release the identifier */
    879875        fibril_rwlock_write_lock(&icmp_globals.lock);
    880876        icmp_echo_data_exclude(&icmp_globals.echo_data, echo_data->identifier);
     
    897893 * @see IS_NET_ICMP_MESSAGE()
    898894 */
    899 int
    900 icmp_message_standalone(ipc_callid_t callid, ipc_call_t *call,
     895int icmp_message_standalone(ipc_callid_t callid, ipc_call_t *call,
    901896    ipc_call_t *answer, int *answer_count)
    902897{
  • uspace/srv/net/tl/icmp/icmp_module.c

    r982e3d8 r8e189ef  
    8585}
    8686
    87 int
    88 tl_module_message_standalone(ipc_callid_t callid, ipc_call_t *call,
     87int tl_module_message_standalone(ipc_callid_t callid, ipc_call_t *call,
    8988    ipc_call_t *answer, int *answer_count)
    9089{
  • uspace/srv/net/tl/tcp/tcp.c

    r982e3d8 r8e189ef  
    4444#include <fibril_synch.h>
    4545#include <malloc.h>
    46 //TODO remove stdio
     46/* TODO remove stdio */
    4747#include <stdio.h>
    4848#include <errno.h>
     
    267267}
    268268
    269 int
    270 tcp_received_msg(device_id_t device_id, packet_t packet, services_t receiver,
    271     services_t error)
     269int tcp_received_msg(device_id_t device_id, packet_t packet,
     270    services_t receiver, services_t error)
    272271{
    273272        int rc;
     
    309308                break;
    310309        case SERVICE_ICMP:
    311                 // process error
     310                /* Process error */
    312311                result = icmp_client_process_packet(packet, &type, &code, NULL,
    313312                    NULL);
     
    324323        }
    325324
    326         // TODO process received ipopts?
     325        /* TODO process received ipopts? */
    327326        result = ip_client_process_packet(packet, NULL, NULL, NULL, NULL, NULL);
    328327        if (result < 0)
     
    338337                return tcp_release_and_return(packet, NO_DATA);
    339338
    340         // trim all but TCP header
     339        /* Trim all but TCP header */
    341340        rc = packet_trim(packet, offset, 0);
    342341        if (rc != EOK)
    343342                return tcp_release_and_return(packet, rc);
    344343
    345         // get tcp header
     344        /* Get tcp header */
    346345        header = (tcp_header_ref) packet_get_data(packet);
    347346        if (!header)
     
    361360                return tcp_release_and_return(packet, rc);
    362361       
    363         // find the destination socket
     362        /* Find the destination socket */
    364363        socket = socket_port_find(&tcp_globals.sockets,
    365364            ntohs(header->destination_port), (const char *) src, addrlen);
    366365        if (!socket) {
    367                 // find the listening destination socket
     366                /* Find the listening destination socket */
    368367                socket = socket_port_find(&tcp_globals.sockets,
    369368                    ntohs(header->destination_port), SOCKET_MAP_KEY_LISTENING,
    370369                    0);
    371370        }
     371
    372372        if (!socket) {
    373373                if (tl_prepare_icmp_packet(tcp_globals.net_phone,
     
    383383        assert(socket_data);
    384384
    385         // some data received, clear the timeout counter
     385        /* Some data received, clear the timeout counter */
    386386        socket_data->timeout_count = 0;
    387387
    388         // count the received packet fragments
     388        /* Count the received packet fragments */
    389389        next_packet = packet;
    390390        fragments = 0;
     
    399399                total_length += length;
    400400
    401                 // add partial checksum if set
     401                /* Add partial checksum if set */
    402402                if (!error) {
    403403                        checksum = compute_checksum(checksum,
     
    447447                    tcp_globals.icmp_phone, packet, error);
    448448                if (rc == EOK) {
    449                         // checksum error ICMP
     449                        /* Checksum error ICMP */
    450450                        icmp_parameter_problem_msg(tcp_globals.icmp_phone,
    451451                            ICMP_PARAM_POINTER,
     
    460460        fibril_rwlock_read_unlock(&tcp_globals.lock);
    461461
    462         // TODO error reporting/handling
     462        /* TODO error reporting/handling */
    463463        switch (socket_data->state) {
    464464        case TCP_SOCKET_LISTEN:
     
    474474                break;
    475475        case TCP_SOCKET_FIN_WAIT_1:
    476                 // ack changing the state to FIN_WAIT_2 gets processed later
     476                /* ack changing the state to FIN_WAIT_2 gets processed later */
    477477        case TCP_SOCKET_FIN_WAIT_2:
    478                 // fin changing state to LAST_ACK gets processed later
     478                /* fin changing state to LAST_ACK gets processed later */
    479479        case TCP_SOCKET_LAST_ACK:
    480                 // ack releasing the socket get processed later
     480                /* ack releasing the socket get processed later */
    481481        case TCP_SOCKET_CLOSING:
    482                 // ack releasing the socket gets processed later
     482                /* ack releasing the socket gets processed later */
    483483        case TCP_SOCKET_ESTABLISHED:
    484484                rc = tcp_process_established(socket, socket_data, header,
     
    497497}
    498498
    499 int
    500 tcp_process_established(socket_core_ref socket, tcp_socket_data_ref socket_data,
    501     tcp_header_ref header, packet_t packet, int fragments, size_t total_length)
     499int tcp_process_established(socket_core_ref socket, tcp_socket_data_ref
     500    socket_data, tcp_header_ref header, packet_t packet, int fragments,
     501    size_t total_length)
    502502{
    503503        packet_t next_packet;
     
    523523                socket_data->fin_incoming = new_sequence_number;
    524524
    525         // trim begining if containing expected data
     525        /* Trim begining if containing expected data */
    526526        if (IS_IN_INTERVAL_OVERFLOW(new_sequence_number,
    527527            socket_data->next_incoming, new_sequence_number + total_length)) {
    528528
    529                 // get the acknowledged offset
     529                /* Get the acknowledged offset */
    530530                if (socket_data->next_incoming < new_sequence_number) {
    531531                        offset = new_sequence_number -
     
    539539                total_length -= offset;
    540540                length = packet_get_data_length(packet);
    541                 // trim the acknowledged data
     541
     542                /* Trim the acknowledged data */
    542543                while (length <= offset) {
    543                         // release the acknowledged packets
     544                        /* Release the acknowledged packets */
    544545                        next_packet = pq_next(packet);
    545546                        pq_release_remote(tcp_globals.net_phone,
     
    559560        }
    560561
    561         // release if overflowing the window
     562        /* Release if overflowing the window */
    562563/*
    563564        if (IS_IN_INTERVAL_OVERFLOW(socket_data->next_incoming +
     
    609610        }
    610611*/
    611         // the expected one arrived?
     612        /* The expected one arrived? */
    612613        if (new_sequence_number == socket_data->next_incoming) {
    613614                printf("expected\n");
    614                 // process acknowledgement
     615                /* Process acknowledgement */
    615616                tcp_process_acknowledgement(socket, socket_data, header);
    616617
    617                 // remove the header
     618                /* Remove the header */
    618619                total_length -= TCP_HEADER_LENGTH(header);
    619620                rc = packet_trim(packet, TCP_HEADER_LENGTH(header), 0);
     
    635636                        rc = pq_get_order(socket_data->incoming, &order, NULL);
    636637                        if (rc != EOK) {
    637                                 // remove the corrupted packet
     638                                /* Remove the corrupted packet */
    638639                                next_packet = pq_detach(packet);
    639640                                if (packet == socket_data->incoming)
     
    648649                        if (IS_IN_INTERVAL_OVERFLOW(sequence_number,
    649650                            old_incoming, socket_data->next_incoming)) {
    650                                 // move to the next
     651                                /* Move to the next */
    651652                                packet = pq_next(packet);
    652                                 // coninual data?
     653                                /* Coninual data? */
    653654                        } else if (IS_IN_INTERVAL_OVERFLOW(old_incoming,
    654655                            sequence_number, socket_data->next_incoming)) {
    655                                 // detach the packet
     656                                /* Detach the packet */
    656657                                next_packet = pq_detach(packet);
    657658                                if (packet == socket_data->incoming)
    658659                                        socket_data->incoming = next_packet;
    659                                 // get data length
     660                                /* Get data length */
    660661                                length = packet_get_data_length(packet);
    661662                                new_sequence_number = sequence_number + length;
    662663                                if (length <= 0) {
    663                                         // remove the empty packet
     664                                        /* Remove the empty packet */
    664665                                        pq_release_remote(tcp_globals.net_phone,
    665666                                            packet_get_id(packet));
     
    667668                                        continue;
    668669                                }
    669                                 // exactly following
     670                                /* Exactly following */
    670671                                if (sequence_number ==
    671672                                    socket_data->next_incoming) {
    672                                         // queue received data
     673                                        /* Queue received data */
    673674                                        rc = tcp_queue_received_packet(socket,
    674675                                            socket_data, packet, 1,
     
    680681                                        packet = next_packet;
    681682                                        continue;
    682                                         // at least partly following data?
     683                                        /* At least partly following data? */
    683684                                }
    684685                                if (IS_IN_INTERVAL_OVERFLOW(sequence_number,
     
    695696                                        rc = packet_trim(packet,length, 0);
    696697                                        if (rc == EOK) {
    697                                                 // queue received data
     698                                                /* Queue received data */
    698699                                                rc = tcp_queue_received_packet(
    699700                                                    socket, socket_data, packet,
     
    708709                                        }
    709710                                }
    710                                 // remove the duplicit or corrupted packet
     711                                /* Remove the duplicit or corrupted packet */
    711712                                pq_release_remote(tcp_globals.net_phone,
    712713                                    packet_get_id(packet));
     
    721722            socket_data->next_incoming + socket_data->window)) {
    722723                printf("in window\n");
    723                 // process acknowledgement
     724                /* Process acknowledgement */
    724725                tcp_process_acknowledgement(socket, socket_data, header);
    725726
    726                 // remove the header
     727                /* Remove the header */
    727728                total_length -= TCP_HEADER_LENGTH(header);
    728729                rc = packet_trim(packet, TCP_HEADER_LENGTH(header), 0);
     
    735736                    length);
    736737                if (rc != EOK) {
    737                         // remove the corrupted packets
     738                        /* Remove the corrupted packets */
    738739                        pq_release_remote(tcp_globals.net_phone,
    739740                            packet_get_id(packet));
     
    762763        } else {
    763764                printf("unexpected\n");
    764                 // release duplicite or restricted
     765                /* Release duplicite or restricted */
    765766                pq_release_remote(tcp_globals.net_phone, packet_get_id(packet));
    766767        }
    767768
    768         // change state according to the acknowledging incoming fin
     769        /* Change state according to the acknowledging incoming fin */
    769770        if (IS_IN_INTERVAL_OVERFLOW(old_incoming, socket_data->fin_incoming,
    770771            socket_data->next_incoming)) {
     
    775776                        socket_data->state = TCP_SOCKET_CLOSING;
    776777                        break;
    777                         //case TCP_ESTABLISHED:
     778                /*case TCP_ESTABLISHED:*/
    778779                default:
    779780                        socket_data->state = TCP_SOCKET_CLOSE_WAIT;
     
    784785        packet = tcp_get_packets_to_send(socket, socket_data);
    785786        if (!packet) {
    786                 // create the notification packet
     787                /* Create the notification packet */
    787788                rc = tcp_create_notification_packet(&packet, socket,
    788789                    socket_data, 0, 0);
     
    798799        fibril_rwlock_write_unlock(socket_data->local_lock);
    799800
    800         // send the packet
     801        /* Send the packet */
    801802        tcp_send_packets(socket_data->device_id, packet);
    802803
     
    804805}
    805806
    806 int
    807 tcp_queue_received_packet(socket_core_ref socket,
     807int tcp_queue_received_packet(socket_core_ref socket,
    808808    tcp_socket_data_ref socket_data, packet_t packet, int fragments,
    809809    size_t total_length)
     
    819819        assert(socket_data->window > total_length);
    820820
    821         // queue the received packet
     821        /* Queue the received packet */
    822822        rc = dyn_fifo_push(&socket->received, packet_get_id(packet),
    823823            SOCKET_MAX_RECEIVED_SIZE);
     
    829829                return tcp_release_and_return(packet, rc);
    830830
    831         // decrease the window size
     831        /* Decrease the window size */
    832832        socket_data->window -= total_length;
    833833
    834         // notify the destination socket
     834        /* Notify the destination socket */
    835835        async_msg_5(socket->phone, NET_SOCKET_RECEIVED,
    836836            (ipcarg_t) socket->socket_id,
     
    842842}
    843843
    844 int
    845 tcp_process_syn_sent(socket_core_ref socket, tcp_socket_data_ref socket_data,
    846     tcp_header_ref header, packet_t packet)
     844int tcp_process_syn_sent(socket_core_ref socket, tcp_socket_data_ref
     845    socket_data, tcp_header_ref header, packet_t packet)
    847846{
    848847        packet_t next_packet;
     
    858857                return tcp_release_and_return(packet, EINVAL);
    859858       
    860         // process acknowledgement
     859        /* Process acknowledgement */
    861860        tcp_process_acknowledgement(socket, socket_data, header);
    862861
    863862        socket_data->next_incoming = ntohl(header->sequence_number) + 1;
    864         // release additional packets
     863
     864        /* Release additional packets */
    865865        next_packet = pq_detach(packet);
    866866        if (next_packet) {
     
    868868                    packet_get_id(next_packet));
    869869        }
    870         // trim if longer than the header
     870
     871        /* Trim if longer than the header */
    871872        if (packet_get_data_length(packet) > sizeof(*header)) {
    872873                rc = packet_trim(packet, 0,
     
    875876                        return tcp_release_and_return(packet, rc);
    876877        }
     878
    877879        tcp_prepare_operation_header(socket, socket_data, header, 0, 0);
    878880        fibril_mutex_lock(&socket_data->operation.mutex);
    879881        socket_data->operation.result = tcp_queue_packet(socket, socket_data,
    880882            packet, 1);
     883
    881884        if (socket_data->operation.result == EOK) {
    882885                socket_data->state = TCP_SOCKET_ESTABLISHED;
     
    884887                if (packet) {
    885888                        fibril_rwlock_write_unlock( socket_data->local_lock);
    886                         // send the packet
     889                        /* Send the packet */
    887890                        tcp_send_packets(socket_data->device_id, packet);
    888                         // signal the result
     891                        /* Signal the result */
    889892                        fibril_condvar_signal( &socket_data->operation.condvar);
    890893                        fibril_mutex_unlock( &socket_data->operation.mutex);
     
    892895                }
    893896        }
     897
    894898        fibril_mutex_unlock(&socket_data->operation.mutex);
    895899        return tcp_release_and_return(packet, EINVAL);
    896900}
    897901
    898 int
    899 tcp_process_listen(socket_core_ref listening_socket,
     902int tcp_process_listen(socket_core_ref listening_socket,
    900903    tcp_socket_data_ref listening_socket_data, tcp_header_ref header,
    901904    packet_t packet, struct sockaddr *src, struct sockaddr *dest,
     
    936939                return tcp_release_and_return(packet, ENOMEM);
    937940        }
     941
    938942        memcpy(socket_data->addr, src, socket_data->addrlen);
    939943        socket_data->dest_port = ntohs(header->source_port);
     
    946950        }
    947951
    948         // create a socket
     952        /* Create a socket */
    949953        socket_id = -1;
    950954        rc = socket_create(socket_data->local_sockets, listening_socket->phone,
     
    965969        fibril_rwlock_write_lock(&tcp_globals.lock);
    966970
    967         // find the destination socket
     971        /* Find the destination socket */
    968972        listening_socket = socket_port_find(&tcp_globals.sockets,
    969973            listening_port, SOCKET_MAP_KEY_LISTENING, 0);
     
    971975            (listening_socket->socket_id != listening_socket_id)) {
    972976                fibril_rwlock_write_unlock(&tcp_globals.lock);
    973                 // a shadow may remain until app hangs up
     977                /* A shadow may remain until app hangs up */
    974978                return tcp_release_and_return(packet, EOK /*ENOTSOCK*/);
    975979        }
     
    983987            socket_id);
    984988        if (!socket) {
    985                 // where is the socket?!?
     989                /* Where is the socket?!? */
    986990                fibril_rwlock_write_unlock(&tcp_globals.lock);
    987991                return ENOTSOCK;
     
    10101014        socket_data->next_incoming = ntohl(header->sequence_number) + 1;
    10111015
    1012         // release additional packets
     1016        /* Release additional packets */
    10131017        next_packet = pq_detach(packet);
    10141018        if (next_packet) {
     
    10171021        }
    10181022
    1019         // trim if longer than the header
     1023        /* Trim if longer than the header */
    10201024        if (packet_get_data_length(packet) > sizeof(*header)) {
    10211025                rc = packet_trim(packet, 0,
     
    10501054        fibril_rwlock_write_unlock(socket_data->local_lock);
    10511055
    1052         // send the packet
     1056        /* Send the packet */
    10531057        tcp_send_packets(socket_data->device_id, packet);
    10541058
     
    10561060}
    10571061
    1058 int
    1059 tcp_process_syn_received(socket_core_ref socket,
     1062int tcp_process_syn_received(socket_core_ref socket,
    10601063    tcp_socket_data_ref socket_data, tcp_header_ref header, packet_t packet)
    10611064{
     
    10731076                return tcp_release_and_return(packet, EINVAL);
    10741077
    1075         // process acknowledgement
     1078        /* Process acknowledgement */
    10761079        tcp_process_acknowledgement(socket, socket_data, header);
    10771080
     
    10861089                assert(listening_socket_data);
    10871090
    1088                 // queue the received packet
     1091                /* Queue the received packet */
    10891092                rc = dyn_fifo_push(&listening_socket->accepted,
    10901093                    (-1 * socket->socket_id), listening_socket_data->backlog);
    10911094                if (rc == EOK) {
    1092                         // notify the destination socket
     1095                        /* Notify the destination socket */
    10931096                        async_msg_5(socket->phone, NET_SOCKET_ACCEPTED,
    10941097                            (ipcarg_t) listening_socket->socket_id,
     
    11001103                }
    11011104        }
    1102         // send FIN
     1105        /* Send FIN */
    11031106        socket_data->state = TCP_SOCKET_FIN_WAIT_1;
    11041107
    1105         // create the notification packet
     1108        /* Create the notification packet */
    11061109        rc = tcp_create_notification_packet(&packet, socket, socket_data, 0, 1);
    11071110        if (rc != EOK)
    11081111                return rc;
    11091112
    1110         // send the packet
     1113        /* Send the packet */
    11111114        rc = tcp_queue_packet(socket, socket_data, packet, 1);
    11121115        if (rc != EOK)
    11131116                return rc;
    11141117
    1115         // flush packets
     1118        /* Flush packets */
    11161119        packet = tcp_get_packets_to_send(socket, socket_data);
    11171120        fibril_rwlock_write_unlock(socket_data->local_lock);
    11181121        if (packet) {
    1119                 // send the packet
     1122                /* Send the packet */
    11201123                tcp_send_packets(socket_data->device_id, packet);
    11211124        }
     
    11241127}
    11251128
    1126 void
    1127 tcp_process_acknowledgement(socket_core_ref socket,
     1129void tcp_process_acknowledgement(socket_core_ref socket,
    11281130    tcp_socket_data_ref socket_data, tcp_header_ref header)
    11291131{
     
    11441146
    11451147        number = ntohl(header->acknowledgement_number);
    1146         // if more data acknowledged
     1148
     1149        /* If more data acknowledged */
    11471150        if (number != socket_data->expected) {
    11481151                old = socket_data->expected;
     
    11551158                        case TCP_SOCKET_LAST_ACK:
    11561159                        case TCP_SOCKET_CLOSING:
    1157                                 // fin acknowledged - release the socket in
    1158                                 // another fibril
     1160                                /*
     1161                                 * FIN acknowledged - release the socket in
     1162                                 * another fibril.
     1163                                 */
    11591164                                tcp_prepare_timeout(tcp_release_after_timeout,
    11601165                                    socket, socket_data, 0,
     
    11661171                        }
    11671172                }
    1168                 // update the treshold if higher than set
     1173
     1174                /* Update the treshold if higher than set */
    11691175                if (number + ntohs(header->window) >
    11701176                    socket_data->expected + socket_data->treshold) {
     
    11721178                            socket_data->expected;
    11731179                }
    1174                 // set new expected sequence number
     1180
     1181                /* Set new expected sequence number */
    11751182                socket_data->expected = number;
    11761183                socket_data->expected_count = 1;
     
    11841191                                        socket_data->outgoing = next;
    11851192
    1186                                 // add to acknowledged or release
     1193                                /* Add to acknowledged or release */
    11871194                                if (pq_add(&acknowledged, packet, 0, 0) != EOK)
    11881195                                        pq_release_remote(tcp_globals.net_phone,
     
    11921199                                break;
    11931200                }
    1194                 // release acknowledged
     1201
     1202                /* Release acknowledged */
    11951203                if (acknowledged) {
    11961204                        pq_release_remote(tcp_globals.net_phone,
     
    11981206                }
    11991207                return;
    1200                 // if the same as the previous time
    1201         }
     1208                /* If the same as the previous time */
     1209        }
     1210
    12021211        if (number == socket_data->expected) {
    1203                 // increase the counter
     1212                /* Increase the counter */
    12041213                socket_data->expected_count++;
    12051214                if (socket_data->expected_count == TCP_FAST_RETRANSMIT_COUNT) {
    12061215                        socket_data->expected_count = 1;
    1207                         // TODO retransmit lock
     1216                        /* TODO retransmit lock */
    12081217                        //tcp_retransmit_packet(socket, socket_data, number);
    12091218                }
     
    13111320        while (keep_on_going) {
    13121321
    1313                 // answer the call
     1322                /* Answer the call */
    13141323                answer_call(callid, res, &answer, answer_count);
    1315                 // refresh data
     1324                /* Refresh data */
    13161325                refresh_answer(&answer, &answer_count);
    1317                 // get the next call
     1326                /* Get the next call */
    13181327                callid = async_get_call(&call);
    13191328
    1320                 // process the call
     1329                /* Process the call */
    13211330                switch (IPC_GET_METHOD(call)) {
    13221331                case IPC_M_PHONE_HUNGUP:
     
    14011410                        if (res != EOK)
    14021411                                break;
    1403                         // the global lock may be released in the
    1404                         // tcp_connect_message() function
     1412                        /*
     1413                         * The global lock may be released in the
     1414                         * tcp_connect_message() function.
     1415                         */
    14051416                        fibril_rwlock_write_lock(&tcp_globals.lock);
    14061417                        fibril_rwlock_write_lock(&lock);
     
    15161527        }
    15171528
    1518         // release the application phone
     1529        /* Release the application phone */
    15191530        ipc_hangup(app_phone);
    15201531
    15211532        printf("release\n");
    1522         // release all local sockets
     1533        /* Release all local sockets */
    15231534        socket_cores_release(tcp_globals.net_phone, &local_sockets,
    15241535            &tcp_globals.sockets, tcp_free_socket_data);
     
    15361547        assert(timeout);
    15371548
    1538         // sleep the given timeout
     1549        /* Sleep the given timeout */
    15391550        async_usleep(timeout->timeout);
    1540         // lock the globals
     1551        /* Lock the globals */
    15411552        if (timeout->globals_read_only)
    15421553                fibril_rwlock_read_lock(&tcp_globals.lock);
     
    15441555                fibril_rwlock_write_lock(&tcp_globals.lock);
    15451556
    1546         // find the pending operation socket
     1557        /* Find the pending operation socket */
    15471558        socket = socket_port_find(&tcp_globals.sockets, timeout->port,
    15481559            timeout->key, timeout->key_length);
     
    15571568        fibril_rwlock_write_lock(socket_data->local_lock);
    15581569        if (timeout->sequence_number) {
    1559                 // increase the timeout counter;
     1570                /* Increase the timeout counter */
    15601571                socket_data->timeout_count++;
    15611572                if (socket_data->timeout_count == TCP_MAX_TIMEOUTS) {
    1562                         // TODO release as connection lost
     1573                        /* TODO release as connection lost */
    15631574                        //tcp_refresh_socket_data(socket_data);
    15641575                        fibril_rwlock_write_unlock(socket_data->local_lock);
    15651576                } else {
    1566                         // retransmit
     1577                        /* Retransmit */
    15671578//                      tcp_retransmit_packet(socket,
    15681579//                          socket_data, timeout->sequence_number);
     
    15711582        } else {
    15721583                fibril_mutex_lock(&socket_data->operation.mutex);
    1573                 // set the timeout operation result if state not
    1574                 // changed
     1584                /* Set the timeout operation result if state not changed */
    15751585                if (socket_data->state == timeout->state) {
    15761586                        socket_data->operation.result = ETIMEOUT;
    1577                         // notify the main fibril
     1587
     1588                        /* Notify the main fibril */
    15781589                        fibril_condvar_signal(&socket_data->operation.condvar);
    1579                         // keep the global write lock
     1590
     1591                        /* Keep the global write lock */
    15801592                        keep_write_lock = true;
    15811593                } else {
    1582                         // operation is ok, do nothing
    1583                         // unlocking from now on, so the unlocki
    1584                         // order does not matter...
     1594                        /*
     1595                         * Operation is ok, do nothing.
     1596                         * Unlocking from now on, so the unlocking
     1597                         * order does not matter.
     1598                         */
    15851599                        fibril_rwlock_write_unlock(socket_data->local_lock);
    15861600                }
     
    15891603
    15901604out:
    1591         // unlock only if no socket
     1605        /* Unlock only if no socket */
    15921606        if (timeout->globals_read_only)
    15931607                fibril_rwlock_read_unlock(&tcp_globals.lock);
    15941608        else if (!keep_write_lock)
    1595                 // release if not desired
     1609                /* Release if not desired */
    15961610                fibril_rwlock_write_unlock(&tcp_globals.lock);
    15971611       
    1598         // release the timeout structure
     1612        /* Release the timeout structure */
    15991613        free(timeout);
    16001614        return EOK;
     
    16101624        assert(timeout);
    16111625
    1612         // sleep the given timeout
     1626        /* Sleep the given timeout */
    16131627        async_usleep(timeout->timeout);
    1614         // lock the globals
     1628
     1629        /* Lock the globals */
    16151630        fibril_rwlock_write_lock(&tcp_globals.lock);
    1616         // find the pending operation socket
     1631
     1632        /* Find the pending operation socket */
    16171633        socket = socket_port_find(&tcp_globals.sockets, timeout->port,
    16181634            timeout->key, timeout->key_length);
     1635
    16191636        if (socket && (socket->socket_id == timeout->socket_id)) {
    16201637                socket_data = (tcp_socket_data_ref) socket->specific_data;
     
    16291646                }
    16301647        }
    1631         // unlock the globals
     1648
     1649        /* Unlock the globals */
    16321650        fibril_rwlock_write_unlock(&tcp_globals.lock);
    1633         // release the timeout structure
     1651
     1652        /* Release the timeout structure */
    16341653        free(timeout);
     1654
    16351655        return EOK;
    16361656}
    16371657
    1638 void
    1639 tcp_retransmit_packet(socket_core_ref socket, tcp_socket_data_ref socket_data,
    1640     size_t sequence_number)
     1658void tcp_retransmit_packet(socket_core_ref socket, tcp_socket_data_ref
     1659    socket_data, size_t sequence_number)
    16411660{
    16421661        packet_t packet;
     
    16481667        assert(socket->specific_data == socket_data);
    16491668
    1650         // sent packet?
     1669        /* Sent packet? */
    16511670        packet = pq_find(socket_data->outgoing, sequence_number);
    16521671        printf("retransmit %d\n", packet_get_id(packet));
     
    16641683}
    16651684
    1666 int
    1667 tcp_listen_message(socket_cores_ref local_sockets, int socket_id, int backlog)
     1685int tcp_listen_message(socket_cores_ref local_sockets, int socket_id,
     1686    int backlog)
    16681687{
    16691688        socket_core_ref socket;
     
    16751694                return EINVAL;
    16761695
    1677         // find the socket
     1696        /* Find the socket */
    16781697        socket = socket_cores_find(local_sockets, socket_id);
    16791698        if (!socket)
    16801699                return ENOTSOCK;
    16811700       
    1682         // get the socket specific data
     1701        /* Get the socket specific data */
    16831702        socket_data = (tcp_socket_data_ref) socket->specific_data;
    16841703        assert(socket_data);
    1685         // set the backlog
     1704
     1705        /* Set the backlog */
    16861706        socket_data->backlog = backlog;
    16871707
     
    16891709}
    16901710
    1691 int
    1692 tcp_connect_message(socket_cores_ref local_sockets, int socket_id,
     1711int tcp_connect_message(socket_cores_ref local_sockets, int socket_id,
    16931712    struct sockaddr *addr, socklen_t addrlen)
    16941713{
     
    17001719        assert(addrlen > 0);
    17011720
    1702         // find the socket
     1721        /* Find the socket */
    17031722        socket = socket_cores_find(local_sockets, socket_id);
    17041723        if (!socket)
     
    17081727        if (rc != EOK) {
    17091728                tcp_free_socket_data(socket);
    1710                 // unbind if bound
     1729                /* Unbind if bound */
    17111730                if (socket->port > 0) {
    17121731                        socket_ports_exclude(&tcp_globals.sockets,
     
    17181737}
    17191738
    1720 int
    1721 tcp_connect_core(socket_core_ref socket, socket_cores_ref local_sockets,
     1739int tcp_connect_core(socket_core_ref socket, socket_cores_ref local_sockets,
    17221740    struct sockaddr *addr, socklen_t addrlen)
    17231741{
     
    17301748        assert(addrlen > 0);
    17311749
    1732         // get the socket specific data
     1750        /* Get the socket specific data */
    17331751        socket_data = (tcp_socket_data_ref) socket->specific_data;
    17341752        assert(socket_data);
     
    17391757                return EINVAL;
    17401758
    1741         // get the destination port
     1759        /* Get the destination port */
    17421760        rc = tl_get_address_port(addr, addrlen, &socket_data->dest_port);
    17431761        if (rc != EOK)
     
    17451763       
    17461764        if (socket->port <= 0) {
    1747                 // try to find a free port
     1765                /* Try to find a free port */
    17481766                rc = socket_bind_free_port(&tcp_globals.sockets, socket,
    17491767                    TCP_FREE_PORTS_START, TCP_FREE_PORTS_END,
     
    17511769                if (rc != EOK)
    17521770                        return rc;
    1753                 // set the next port as the search starting port number
     1771                /* Set the next port as the search starting port number */
    17541772                tcp_globals.last_used_port = socket->port;
    17551773        }
     
    17611779                return rc;
    17621780
    1763         // create the notification packet
     1781        /* Create the notification packet */
    17641782        rc = tcp_create_notification_packet(&packet, socket, socket_data, 1, 0);
    17651783        if (rc != EOK)
    17661784                return rc;
    17671785
    1768         // unlock the globals and wait for an operation
     1786        /* Unlock the globals and wait for an operation */
    17691787        fibril_rwlock_write_unlock(&tcp_globals.lock);
    17701788
    17711789        socket_data->addr = addr;
    17721790        socket_data->addrlen = addrlen;
    1773         // send the packet
     1791
     1792        /* Send the packet */
    17741793
    17751794        if (((rc = tcp_queue_packet(socket, socket_data, packet, 1)) != EOK) ||
     
    17851804                        fibril_mutex_lock(&socket_data->operation.mutex);
    17861805                        fibril_rwlock_write_unlock(socket_data->local_lock);
    1787                         // send the packet
     1806
     1807                        /* Send the packet */
    17881808                        printf("connecting %d\n", packet_get_id(packet));
    17891809                        tcp_send_packets(socket_data->device_id, packet);
    17901810
    1791                         // wait for a reply
     1811                        /* Wait for a reply */
    17921812                        fibril_condvar_wait(&socket_data->operation.condvar,
    17931813                            &socket_data->operation.mutex);
     
    18051825
    18061826        fibril_mutex_unlock(&socket_data->operation.mutex);
    1807 
    1808         // return the result
    18091827        return rc;
    18101828}
    18111829
    1812 int
    1813 tcp_queue_prepare_packet(socket_core_ref socket,
     1830int tcp_queue_prepare_packet(socket_core_ref socket,
    18141831    tcp_socket_data_ref socket_data, packet_t packet, size_t data_length)
    18151832{
     
    18211838        assert(socket->specific_data == socket_data);
    18221839
    1823         // get tcp header
     1840        /* Get TCP header */
    18241841        header = (tcp_header_ref) packet_get_data(packet);
    18251842        if (!header)
     
    18351852                return tcp_release_and_return(packet, EINVAL);
    18361853
    1837         // remember the outgoing FIN
     1854        /* Remember the outgoing FIN */
    18381855        if (header->finalize)
    18391856                socket_data->fin_outgoing = socket_data->next_outgoing;
     
    18421859}
    18431860
    1844 int
    1845 tcp_queue_packet(socket_core_ref socket, tcp_socket_data_ref socket_data,
     1861int tcp_queue_packet(socket_core_ref socket, tcp_socket_data_ref socket_data,
    18461862    packet_t packet, size_t data_length)
    18471863{
     
    18651881}
    18661882
    1867 packet_t
    1868 tcp_get_packets_to_send(socket_core_ref socket, tcp_socket_data_ref socket_data)
     1883packet_t tcp_get_packets_to_send(socket_core_ref socket, tcp_socket_data_ref
     1884    socket_data)
    18691885{
    18701886        packet_t packet;
     
    18831899                pq_get_order(packet, NULL, &data_length);
    18841900
    1885                 // send only if fits into the window
    1886                 // respecting the possible overflow
     1901                /*
     1902                 * Send only if fits into the window, respecting the possible
     1903                 * overflow.
     1904                 */
    18871905                if (!IS_IN_INTERVAL_OVERFLOW(
    18881906                    (uint32_t) socket_data->last_outgoing,
     
    19091927                previous = copy;
    19101928                packet = pq_next(packet);
    1911                 // overflow occurred ?
     1929
     1930                /* Overflow occurred? */
    19121931                if (!packet &&
    19131932                    (socket_data->last_outgoing > socket_data->next_outgoing)) {
    19141933                        printf("gpts overflow\n");
    1915                         // continue from the beginning
     1934                        /* Continue from the beginning */
    19161935                        packet = socket_data->outgoing;
    19171936                }
     
    19221941}
    19231942
    1924 packet_t
    1925 tcp_send_prepare_packet(socket_core_ref socket, tcp_socket_data_ref socket_data,
    1926     packet_t packet, size_t data_length, size_t sequence_number)
     1943packet_t tcp_send_prepare_packet(socket_core_ref socket, tcp_socket_data_ref
     1944    socket_data, packet_t packet, size_t data_length, size_t sequence_number)
    19271945{
    19281946        tcp_header_ref header;
     
    19341952        assert(socket->specific_data == socket_data);
    19351953
    1936         // adjust the pseudo header
     1954        /* Adjust the pseudo header */
    19371955        rc = ip_client_set_pseudo_header_data_length(socket_data->pseudo_header,
    19381956            socket_data->headerlen, packet_get_data_length(packet));
     
    19421960        }
    19431961
    1944         // get the header
     1962        /* Get the header */
    19451963        header = (tcp_header_ref) packet_get_data(packet);
    19461964        if (!header) {
     
    19501968        assert(ntohl(header->sequence_number) == sequence_number);
    19511969
    1952         // adjust the header
     1970        /* Adjust the header */
    19531971        if (socket_data->next_incoming) {
    19541972                header->acknowledgement_number =
     
    19581976        header->window = htons(socket_data->window);
    19591977
    1960         // checksum
     1978        /* Checksum */
    19611979        header->checksum = 0;
    19621980        checksum = compute_checksum(0, socket_data->pseudo_header,
     
    19671985        header->checksum = htons(flip_checksum(compact_checksum(checksum)));
    19681986
    1969         // prepare the packet
     1987        /* Prepare the packet */
    19701988        rc = ip_client_prepare_packet(packet, IPPROTO_TCP, 0, 0, 0, 0);
    19711989        if (rc != EOK) {
     
    19731991                return NULL;
    19741992        }
     1993
    19751994        rc = tcp_prepare_timeout(tcp_timeout, socket, socket_data,
    19761995            sequence_number, socket_data->state, socket_data->timeout, true);
     
    19832002}
    19842003
    1985 packet_t
    1986 tcp_prepare_copy(socket_core_ref socket, tcp_socket_data_ref socket_data,
    1987     packet_t packet, size_t data_length, size_t sequence_number)
     2004packet_t tcp_prepare_copy(socket_core_ref socket, tcp_socket_data_ref
     2005    socket_data, packet_t packet, size_t data_length, size_t sequence_number)
    19882006{
    19892007        packet_t copy;
     
    19932011        assert(socket->specific_data == socket_data);
    19942012
    1995         // make a copy of the packet
     2013        /* Make a copy of the packet */
    19962014        copy = packet_get_copy(tcp_globals.net_phone, packet);
    19972015        if (!copy)
     
    20142032}
    20152033
    2016 void
    2017 tcp_prepare_operation_header(socket_core_ref socket,
     2034void tcp_prepare_operation_header(socket_core_ref socket,
    20182035    tcp_socket_data_ref socket_data, tcp_header_ref header, int synchronize,
    20192036    int finalize)
     
    20322049}
    20332050
    2034 int
    2035 tcp_prepare_timeout(int (*timeout_function)(void *tcp_timeout_t),
     2051int tcp_prepare_timeout(int (*timeout_function)(void *tcp_timeout_t),
    20362052    socket_core_ref socket, tcp_socket_data_ref socket_data,
    20372053    size_t sequence_number, tcp_socket_state_t state, suseconds_t timeout,
     
    20452061        assert(socket->specific_data == socket_data);
    20462062
    2047         // prepare the timeout with key bundle structure
     2063        /* Prepare the timeout with key bundle structure */
    20482064        operation_timeout = malloc(sizeof(*operation_timeout) +
    20492065            socket->key_length + 1);
     
    20602076        operation_timeout->state = state;
    20612077
    2062         // copy the key
     2078        /* Copy the key */
    20632079        operation_timeout->key = ((char *) operation_timeout) +
    20642080            sizeof(*operation_timeout);
     
    20672083        operation_timeout->key[operation_timeout->key_length] = '\0';
    20682084
    2069         // prepare the timeouting thread
     2085        /* Prepare the timeouting thread */
    20702086        fibril = fibril_create(timeout_function, operation_timeout);
    20712087        if (!fibril) {
     
    20742090        }
    20752091//      fibril_mutex_lock(&socket_data->operation.mutex);
    2076         // start the timeouting fibril
     2092        /* Start the timeout fibril */
    20772093        fibril_add_ready(fibril);
    20782094        //socket_data->state = state;
     
    20802096}
    20812097
    2082 int
    2083 tcp_recvfrom_message(socket_cores_ref local_sockets, int socket_id, int flags,
    2084     size_t *addrlen)
     2098int tcp_recvfrom_message(socket_cores_ref local_sockets, int socket_id,
     2099    int flags, size_t *addrlen)
    20852100{
    20862101        socket_core_ref socket;
     
    20932108        assert(local_sockets);
    20942109
    2095         // find the socket
     2110        /* Find the socket */
    20962111        socket = socket_cores_find(local_sockets, socket_id);
    20972112        if (!socket)
    20982113                return ENOTSOCK;
    20992114
    2100         // get the socket specific data
     2115        /* Get the socket specific data */
    21012116        if (!socket->specific_data)
    21022117                return NO_DATA;
     
    21042119        socket_data = (tcp_socket_data_ref) socket->specific_data;
    21052120
    2106         // check state
     2121        /* Check state */
    21072122        if ((socket_data->state != TCP_SOCKET_ESTABLISHED) &&
    21082123            (socket_data->state != TCP_SOCKET_CLOSE_WAIT))
    21092124                return ENOTCONN;
    21102125
    2111         // send the source address if desired
     2126        /* Send the source address if desired */
    21122127        if (addrlen) {
    21132128                rc = data_reply(socket_data->addr, socket_data->addrlen);
     
    21172132        }
    21182133
    2119         // get the next received packet
     2134        /* Get the next received packet */
    21202135        packet_id = dyn_fifo_value(&socket->received);
    21212136        if (packet_id < 0)
     
    21262141                return rc;
    21272142
    2128         // reply the packets
     2143        /* Reply the packets */
    21292144        rc = socket_reply_packets(packet, &length);
    21302145        if (rc != EOK)
    21312146                return rc;
    21322147
    2133         // release the packet
     2148        /* Release the packet */
    21342149        dyn_fifo_pop(&socket->received);
    21352150        pq_release_remote(tcp_globals.net_phone, packet_get_id(packet));
    2136         // return the total length
     2151
     2152        /* Return the total length */
    21372153        return (int) length;
    21382154}
    21392155
    2140 int
    2141 tcp_send_message(socket_cores_ref local_sockets, int socket_id, int fragments,
    2142     size_t *data_fragment_size, int flags)
     2156int tcp_send_message(socket_cores_ref local_sockets, int socket_id,
     2157    int fragments, size_t *data_fragment_size, int flags)
    21432158{
    21442159        socket_core_ref socket;
     
    21552170        assert(data_fragment_size);
    21562171
    2157         // find the socket
     2172        /* Find the socket */
    21582173        socket = socket_cores_find(local_sockets, socket_id);
    21592174        if (!socket)
    21602175                return ENOTSOCK;
    21612176
    2162         // get the socket specific data
     2177        /* Get the socket specific data */
    21632178        if (!socket->specific_data)
    21642179                return NO_DATA;
     
    21662181        socket_data = (tcp_socket_data_ref) socket->specific_data;
    21672182
    2168         // check state
     2183        /* Check state */
    21692184        if ((socket_data->state != TCP_SOCKET_ESTABLISHED) &&
    21702185            (socket_data->state != TCP_SOCKET_CLOSE_WAIT))
     
    21812196
    21822197        for (index = 0; index < fragments; index++) {
    2183                 // read the data fragment
     2198                /* Read the data fragment */
    21842199                result = tl_socket_read_packet_data(tcp_globals.net_phone,
    21852200                    &packet, TCP_HEADER_SIZE, packet_dimension,
     
    21892204
    21902205                total_length = (size_t) result;
    2191                 // prefix the tcp header
     2206
     2207                /* Prefix the TCP header */
    21922208                header = PACKET_PREFIX(packet, tcp_header_t);
    21932209                if (!header)
     
    22002216        }
    22012217
    2202         // flush packets
     2218        /* Flush packets */
    22032219        packet = tcp_get_packets_to_send(socket, socket_data);
    22042220        fibril_rwlock_write_unlock(socket_data->local_lock);
     
    22062222
    22072223        if (packet) {
    2208                 // send the packet
     2224                /* Send the packet */
    22092225                tcp_send_packets(socket_data->device_id, packet);
    22102226        }
     
    22212237        int rc;
    22222238
    2223         // find the socket
     2239        /* Find the socket */
    22242240        socket = socket_cores_find(local_sockets, socket_id);
    22252241        if (!socket)
    22262242                return ENOTSOCK;
    22272243
    2228         // get the socket specific data
     2244        /* Get the socket specific data */
    22292245        socket_data = (tcp_socket_data_ref) socket->specific_data;
    22302246        assert(socket_data);
    22312247
    2232         // check state
     2248        /* Check state */
    22332249        switch (socket_data->state) {
    22342250        case TCP_SOCKET_ESTABLISHED:
     
    22432259
    22442260        default:
    2245                 // just destroy
     2261                /* Just destroy */
    22462262                rc = socket_destroy(tcp_globals.net_phone, socket_id,
    22472263                    local_sockets, &tcp_globals.sockets,
     
    22542270        }
    22552271
    2256         // send FIN
    2257         // TODO should I wait to complete?
    2258 
    2259         // create the notification packet
     2272        /*
     2273         * Send FIN.
     2274         * TODO should I wait to complete?
     2275         */
     2276
     2277        /* Create the notification packet */
    22602278        rc = tcp_create_notification_packet(&packet, socket, socket_data, 0, 1);
    22612279        if (rc != EOK)
    22622280                return rc;
    22632281
    2264         // send the packet
     2282        /* Send the packet */
    22652283        rc = tcp_queue_packet(socket, socket_data, packet, 1);
    22662284        if (rc != EOK)
    22672285                return rc;
    22682286
    2269         // flush packets
     2287        /* Flush packets */
    22702288        packet = tcp_get_packets_to_send(socket, socket_data);
    22712289        fibril_rwlock_write_unlock(socket_data->local_lock);
     
    22732291
    22742292        if (packet) {
    2275                 // send the packet
     2293                /* Send the packet */
    22762294                tcp_send_packets(socket_data->device_id, packet);
    22772295        }
     
    22802298}
    22812299
    2282 int
    2283 tcp_create_notification_packet(packet_t *packet, socket_core_ref socket,
     2300int tcp_create_notification_packet(packet_t *packet, socket_core_ref socket,
    22842301    tcp_socket_data_ref socket_data, int synchronize, int finalize)
    22852302{
     
    22902307        assert(packet);
    22912308
    2292         // get the device packet dimension
     2309        /* Get the device packet dimension */
    22932310        rc = tl_get_ip_packet_dimension(tcp_globals.ip_phone,
    22942311            &tcp_globals.dimensions, socket_data->device_id, &packet_dimension);
     
    22962313                return rc;
    22972314
    2298         // get a new packet
     2315        /* Get a new packet */
    22992316        *packet = packet_get_4_remote(tcp_globals.net_phone, TCP_HEADER_SIZE,
    23002317            packet_dimension->addr_len, packet_dimension->prefix,
     
    23042321                return ENOMEM;
    23052322
    2306         // allocate space in the packet
     2323        /* Allocate space in the packet */
    23072324        header = PACKET_SUFFIX(*packet, tcp_header_t);
    23082325        if (!header)
     
    23152332}
    23162333
    2317 int
    2318 tcp_accept_message(socket_cores_ref local_sockets, int socket_id,
     2334int tcp_accept_message(socket_cores_ref local_sockets, int socket_id,
    23192335    int new_socket_id, size_t *data_fragment_size, size_t *addrlen)
    23202336{
     
    23292345        assert(addrlen);
    23302346
    2331         // find the socket
     2347        /* Find the socket */
    23322348        socket = socket_cores_find(local_sockets, socket_id);
    23332349        if (!socket)
    23342350                return ENOTSOCK;
    23352351
    2336         // get the socket specific data
     2352        /* Get the socket specific data */
    23372353        socket_data = (tcp_socket_data_ref) socket->specific_data;
    23382354        assert(socket_data);
    23392355
    2340         // check state
     2356        /* Check state */
    23412357        if (socket_data->state != TCP_SOCKET_LISTEN)
    23422358                return EINVAL;
     
    23522368                        return ENOTSOCK;
    23532369
    2354                 // get the socket specific data
     2370                /* Get the socket specific data */
    23552371                socket_data = (tcp_socket_data_ref) accepted->specific_data;
    23562372                assert(socket_data);
    2357                 // TODO can it be in another state?
     2373                /* TODO can it be in another state? */
    23582374                if (socket_data->state == TCP_SOCKET_ESTABLISHED) {
    23592375                        rc = data_reply(socket_data->addr,
     
    23892405}
    23902406
    2391 void
    2392 tcp_free_socket_data(socket_core_ref socket)
     2407void tcp_free_socket_data(socket_core_ref socket)
    23932408{
    23942409        tcp_socket_data_ref socket_data;
     
    23982413        printf("destroy_socket %d\n", socket->socket_id);
    23992414
    2400         // get the socket specific data
     2415        /* Get the socket specific data */
    24012416        socket_data = (tcp_socket_data_ref) socket->specific_data;
    24022417        assert(socket_data);
    2403         //free the pseudo header
     2418
     2419        /* Free the pseudo header */
    24042420        if (socket_data->pseudo_header) {
    24052421                if (socket_data->headerlen) {
     
    24102426                socket_data->pseudo_header = NULL;
    24112427        }
     2428
    24122429        socket_data->headerlen = 0;
    2413         // free the address
     2430
     2431        /* Free the address */
    24142432        if (socket_data->addr) {
    24152433                if (socket_data->addrlen) {
     
    24732491
    24742492                /*
    2475                    Answer the message
     2493                 * Answer the message
    24762494                 */
    24772495                answer_call(callid, res, &answer, answer_count);
  • uspace/srv/net/tl/tcp/tcp_module.c

    r982e3d8 r8e189ef  
    8686}
    8787
    88 int
    89 tl_module_message_standalone(ipc_callid_t callid, ipc_call_t *call,
     88int tl_module_message_standalone(ipc_callid_t callid, ipc_call_t *call,
    9089    ipc_call_t *answer, int *answer_count)
    9190{
  • uspace/srv/net/tl/udp/udp.c

    r982e3d8 r8e189ef  
    130130        }
    131131
    132         // read default packet dimensions
     132        /* Read default packet dimensions */
    133133        rc = ip_packet_size_req(udp_globals.ip_phone, -1,
    134134            &udp_globals.packet_dimension);
     
    158158        udp_globals.autobinding = NET_DEFAULT_UDP_AUTOBINDING;
    159159
    160         // get configuration
     160        /* Get configuration */
    161161        configuration = &names[0];
    162162        rc = net_get_conf_req(udp_globals.net_phone, &configuration, count,
     
    217217 *                      ip_client_process_packet() function.
    218218 */
    219 static int
    220 udp_process_packet(device_id_t device_id, packet_t packet, services_t error)
     219static int udp_process_packet(device_id_t device_id, packet_t packet,
     220    services_t error)
    221221{
    222222        size_t length;
     
    242242                break;
    243243        case SERVICE_ICMP:
    244                 // ignore error
     244                /* Ignore error */
    245245                // length = icmp_client_header_length(packet);
    246                 // process error
     246
     247                /* Process error */
    247248                result = icmp_client_process_packet(packet, &type,
    248249                    &code, NULL, NULL);
     
    258259        }
    259260
    260         // TODO process received ipopts?
     261        /* TODO process received ipopts? */
    261262        result = ip_client_process_packet(packet, NULL, NULL, NULL, NULL, NULL);
    262263        if (result < 0)
     
    270271                return udp_release_and_return(packet, NO_DATA);
    271272
    272         // trim all but UDP header
     273        /* Trim all but UDP header */
    273274        rc = packet_trim(packet, offset, 0);
    274275        if (rc != EOK)
    275276                return udp_release_and_return(packet, rc);
    276277
    277         // get udp header
     278        /* Get UDP header */
    278279        header = (udp_header_ref) packet_get_data(packet);
    279280        if (!header)
    280281                return udp_release_and_return(packet, NO_DATA);
    281282
    282         // find the destination socket
     283        /* Find the destination socket */
    283284        socket = socket_port_find(&udp_globals.sockets,
    284285        ntohs(header->destination_port), SOCKET_MAP_KEY_LISTENING, 0);
     
    292293        }
    293294
    294         // count the received packet fragments
     295        /* Count the received packet fragments */
    295296        next_packet = packet;
    296297        fragments = 0;
    297298        total_length = ntohs(header->total_length);
    298299
    299         // compute header checksum if set
     300        /* Compute header checksum if set */
    300301        if (header->checksum && !error) {
    301302                result = packet_get_addr(packet, (uint8_t **) &src,
     
    310311                } else {
    311312                        checksum = compute_checksum(0, ip_header, length);
    312                         // the udp header checksum will be added with the first
    313                         // fragment later
     313                        /*
     314                         * The udp header checksum will be added with the first
     315                         * fragment later.
     316                         */
    314317                        free(ip_header);
    315318                }
     
    330333                                return udp_release_and_return(packet, rc);
    331334
    332                         // add partial checksum if set
     335                        /* Add partial checksum if set */
    333336                        if (header->checksum) {
    334337                                checksum = compute_checksum(checksum,
     
    337340                        }
    338341
    339                         // relese the rest of the packet fragments
     342                        /* Relese the rest of the packet fragments */
    340343                        tmp_packet = pq_next(next_packet);
    341344                        while (tmp_packet) {
     
    346349                        }
    347350
    348                         // exit the loop
     351                        /* Exit the loop */
    349352                        break;
    350353                }
    351354                total_length -= length;
    352355
    353                 // add partial checksum if set
     356                /* Add partial checksum if set */
    354357                if (header->checksum) {
    355358                        checksum = compute_checksum(checksum,
     
    360363        } while ((next_packet = pq_next(next_packet)) && (total_length > 0));
    361364
    362         // check checksum
     365        /* Verify checksum */
    363366        if (header->checksum) {
    364367                if (flip_checksum(compact_checksum(checksum)) !=
     
    366369                        if (tl_prepare_icmp_packet(udp_globals.net_phone,
    367370                            udp_globals.icmp_phone, packet, error) == EOK) {
    368                                 // checksum error ICMP
     371                                /* Checksum error ICMP */
    369372                                icmp_parameter_problem_msg(
    370373                                    udp_globals.icmp_phone, ICMP_PARAM_POINTER,
     
    376379        }
    377380
    378         // queue the received packet
     381        /* Queue the received packet */
    379382        rc = dyn_fifo_push(&socket->received, packet_get_id(packet),
    380383            SOCKET_MAX_RECEIVED_SIZE);
     
    387390                return udp_release_and_return(packet, rc);
    388391
    389         // notify the destination socket
     392        /* Notify the destination socket */
    390393        fibril_rwlock_write_unlock(&udp_globals.lock);
    391394        async_msg_5(socket->phone, NET_SOCKET_RECEIVED,
     
    410413 *                      udp_process_packet() function.
    411414 */
    412 static int
    413 udp_received_msg(device_id_t device_id, packet_t packet, services_t receiver,
    414     services_t error)
     415static int udp_received_msg(device_id_t device_id, packet_t packet,
     416    services_t receiver, services_t error)
    415417{
    416418        int result;
     
    451453 *                      function.
    452454 */
    453 static int
    454 udp_sendto_message(socket_cores_ref local_sockets, int socket_id,
     455static int udp_sendto_message(socket_cores_ref local_sockets, int socket_id,
    455456    const struct sockaddr *addr, socklen_t addrlen, int fragments,
    456457    size_t *data_fragment_size, int flags)
     
    480481
    481482        if ((socket->port <= 0) && udp_globals.autobinding) {
    482                 // bind the socket to a random free port if not bound
     483                /* Bind the socket to a random free port if not bound */
    483484                rc = socket_bind_free_port(&udp_globals.sockets, socket,
    484485                    UDP_FREE_PORTS_START, UDP_FREE_PORTS_END,
     
    486487                if (rc != EOK)
    487488                        return rc;
    488                 // set the next port as the search starting port number
     489                /* Set the next port as the search starting port number */
    489490                udp_globals.last_used_port = socket->port;
    490491        }
     
    495496                if (rc != EOK)
    496497                        return rc;
    497                 // get the device packet dimension
     498                /* Get the device packet dimension */
    498499//              rc = tl_get_ip_packet_dimension(udp_globals.ip_phone,
    499500//                  &udp_globals.dimensions, device_id, &packet_dimension);
     
    502503        }
    503504//      } else {
    504                 // do not ask all the time
     505                /* Do not ask all the time */
    505506                rc = ip_packet_size_req(udp_globals.ip_phone, -1,
    506507                    &udp_globals.packet_dimension);
     
    510511//      }
    511512
    512         // read the first packet fragment
     513        /* Read the first packet fragment */
    513514        result = tl_socket_read_packet_data(udp_globals.net_phone, &packet,
    514515            UDP_HEADER_SIZE, packet_dimension, addr, addrlen);
     
    523524                checksum = 0;
    524525
    525         // prefix the udp header
     526        /* Prefix the UDP header */
    526527        header = PACKET_PREFIX(packet, udp_header_t);
    527528        if (!header)
     
    529530
    530531        bzero(header, sizeof(*header));
    531         // read the rest of the packet fragments
     532
     533        /* Read the rest of the packet fragments */
    532534        for (index = 1; index < fragments; index++) {
    533535                result = tl_socket_read_packet_data(udp_globals.net_phone,
     
    548550        }
    549551
    550         // set the udp header
     552        /* Set the UDP header */
    551553        header->source_port = htons((socket->port > 0) ? socket->port : 0);
    552554        header->destination_port = htons(dest_port);
    553555        header->total_length = htons(total_length + sizeof(*header));
    554556        header->checksum = 0;
     557
    555558        if (udp_globals.checksum_computing) {
    556                 // update the pseudo header
     559                /* Update the pseudo header */
    557560                rc = ip_client_set_pseudo_header_data_length(ip_header,
    558561                    headerlen, total_length + UDP_HEADER_SIZE);
     
    562565                }
    563566
    564                 // finish the checksum computation
     567                /* Finish the checksum computation */
    565568                checksum = compute_checksum(checksum, ip_header, headerlen);
    566569                checksum = compute_checksum(checksum, (uint8_t *) header,
     
    573576        }
    574577
    575         // prepare the first packet fragment
     578        /* Prepare the first packet fragment */
    576579        rc = ip_client_prepare_packet(packet, IPPROTO_UDP, 0, 0, 0, 0);
    577580        if (rc != EOK)
     
    581584        fibril_rwlock_write_unlock(&udp_globals.lock);
    582585
    583         // send the packet
     586        /* Send the packet */
    584587        ip_send_msg(udp_globals.ip_phone, device_id, packet, SERVICE_UDP, 0);
    585588
     
    606609 *                      function.
    607610 */
    608 static int
    609 udp_recvfrom_message(socket_cores_ref local_sockets, int socket_id, int flags,
    610     size_t *addrlen)
     611static int udp_recvfrom_message(socket_cores_ref local_sockets, int socket_id,
     612    int flags, size_t *addrlen)
    611613{
    612614        socket_core_ref socket;
     
    620622        int rc;
    621623
    622         // find the socket
     624        /* Find the socket */
    623625        socket = socket_cores_find(local_sockets, socket_id);
    624626        if (!socket)
    625627                return ENOTSOCK;
    626628
    627         // get the next received packet
     629        /* Get the next received packet */
    628630        packet_id = dyn_fifo_value(&socket->received);
    629631        if (packet_id < 0)
     
    636638        }
    637639
    638         // get udp header
     640        /* Get UDP header */
    639641        data = packet_get_data(packet);
    640642        if (!data) {
     
    644646        header = (udp_header_ref) data;
    645647
    646         // set the source address port
     648        /* Set the source address port */
    647649        result = packet_get_addr(packet, (uint8_t **) &addr, NULL);
    648650        rc = tl_set_address_port(addr, result, ntohs(header->source_port));
     
    653655        *addrlen = (size_t) result;
    654656
    655         // send the source address
     657        /* Send the source address */
    656658        rc = data_reply(addr, *addrlen);
    657659        switch (rc) {
     
    665667        }
    666668
    667         // trim the header
     669        /* Trim the header */
    668670        rc = packet_trim(packet, UDP_HEADER_SIZE, 0);
    669671        if (rc != EOK) {
     
    672674        }
    673675
    674         // reply the packets
     676        /* Reply the packets */
    675677        rc = socket_reply_packets(packet, &length);
    676678        switch (rc) {
     
    686688        (void) dyn_fifo_pop(&socket->received);
    687689
    688         // release the packet and return the total length
     690        /* Release the packet and return the total length */
    689691        return udp_release_and_return(packet, (int) length);
    690692}
     
    721723        answer_count = 0;
    722724
    723         // The client connection is only in one fibril and therefore no
    724         // additional locks are needed.
     725        /*
     726         * The client connection is only in one fibril and therefore no
     727         * additional locks are needed.
     728         */
    725729
    726730        socket_cores_initialize(&local_sockets);
     
    728732        while (keep_on_going) {
    729733
    730                 // answer the call
     734                /* Answer the call */
    731735                answer_call(callid, res, &answer, answer_count);
    732736
    733                 // refresh data
     737                /* Refresh data */
    734738                refresh_answer(&answer, &answer_count);
    735739
    736                 // get the next call
     740                /* Get the next call */
    737741                callid = async_get_call(&call);
    738742
    739                 // process the call
     743                /* Process the call */
    740744                switch (IPC_GET_METHOD(call)) {
    741745                case IPC_M_PHONE_HUNGUP:
     
    831835        }
    832836
    833         // release the application phone
     837        /* Release the application phone */
    834838        ipc_hangup(app_phone);
    835839
    836         // release all local sockets
     840        /* Release all local sockets */
    837841        socket_cores_release(udp_globals.net_phone, &local_sockets,
    838842            &udp_globals.sockets, NULL);
     
    854858 * @see IS_NET_UDP_MESSAGE()
    855859 */
    856 int
    857 udp_message_standalone(ipc_callid_t callid, ipc_call_t *call,
     860int udp_message_standalone(ipc_callid_t callid, ipc_call_t *call,
    858861    ipc_call_t *answer, int *answer_count)
    859862{
  • uspace/srv/net/tl/udp/udp_module.c

    r982e3d8 r8e189ef  
    8686}
    8787
    88 int
    89 tl_module_message_standalone(ipc_callid_t callid, ipc_call_t *call,
     88int tl_module_message_standalone(ipc_callid_t callid, ipc_call_t *call,
    9089    ipc_call_t *answer, int *answer_count)
    9190{
Note: See TracChangeset for help on using the changeset viewer.