| 1 | /*
|
|---|
| 2 | * Copyright (c) 2009 Lukas Mejdrech
|
|---|
| 3 | * All rights reserved.
|
|---|
| 4 | *
|
|---|
| 5 | * Redistribution and use in source and binary forms, with or without
|
|---|
| 6 | * modification, are permitted provided that the following conditions
|
|---|
| 7 | * are met:
|
|---|
| 8 | *
|
|---|
| 9 | * - Redistributions of source code must retain the above copyright
|
|---|
| 10 | * notice, this list of conditions and the following disclaimer.
|
|---|
| 11 | * - Redistributions in binary form must reproduce the above copyright
|
|---|
| 12 | * notice, this list of conditions and the following disclaimer in the
|
|---|
| 13 | * documentation and/or other materials provided with the distribution.
|
|---|
| 14 | * - The name of the author may not be used to endorse or promote products
|
|---|
| 15 | * derived from this software without specific prior written permission.
|
|---|
| 16 | *
|
|---|
| 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|---|
| 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|---|
| 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|---|
| 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|---|
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|---|
| 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|---|
| 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|---|
| 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|---|
| 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|---|
| 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|---|
| 27 | */
|
|---|
| 28 |
|
|---|
| 29 | /** @addtogroup net
|
|---|
| 30 | * @{
|
|---|
| 31 | */
|
|---|
| 32 |
|
|---|
| 33 | /** @file
|
|---|
| 34 | * Starts the networking subsystem.
|
|---|
| 35 | * Performs self test if configured to.
|
|---|
| 36 | * @see configuration.h
|
|---|
| 37 | */
|
|---|
| 38 |
|
|---|
| 39 | #include <async.h>
|
|---|
| 40 | #include <stdio.h>
|
|---|
| 41 | #include <task.h>
|
|---|
| 42 |
|
|---|
| 43 | #include <ipc/ipc.h>
|
|---|
| 44 | #include <ipc/services.h>
|
|---|
| 45 |
|
|---|
| 46 | #include "../../err.h"
|
|---|
| 47 | #include "../../modules.h"
|
|---|
| 48 | #include "../../self_test.h"
|
|---|
| 49 |
|
|---|
| 50 | #include "../net_messages.h"
|
|---|
| 51 |
|
|---|
| 52 | /** Networking startup module name.
|
|---|
| 53 | */
|
|---|
| 54 | #define NAME "Networking startup"
|
|---|
| 55 |
|
|---|
| 56 | /** Module entry point.
|
|---|
| 57 | * @param[in] argc The number of command line parameters.
|
|---|
| 58 | * @param[in] argv The command line parameters.
|
|---|
| 59 | * @returns EOK on success.
|
|---|
| 60 | * @returns EINVAL if the net module cannot be started.
|
|---|
| 61 | * @returns Other error codes as defined for the self_test() function.
|
|---|
| 62 | * @returns Other error codes as defined for the NET_NET_STARTUP message.
|
|---|
| 63 | */
|
|---|
| 64 | int main(int argc, char * argv[]);
|
|---|
| 65 |
|
|---|
| 66 | /** Starts the module.
|
|---|
| 67 | * @param[in] fname The module absolute name.
|
|---|
| 68 | * @returns The started module task identifier.
|
|---|
| 69 | * @returns Other error codes as defined for the task_spawn() function.
|
|---|
| 70 | */
|
|---|
| 71 | task_id_t spawn(const char * fname);
|
|---|
| 72 |
|
|---|
| 73 | int main(int argc, char * argv[]){
|
|---|
| 74 | ERROR_DECLARE;
|
|---|
| 75 |
|
|---|
| 76 | int net_phone;
|
|---|
| 77 |
|
|---|
| 78 | // print the module label
|
|---|
| 79 | printf("Task %d - ", task_get_id());
|
|---|
| 80 | printf("%s\n", NAME);
|
|---|
| 81 |
|
|---|
| 82 | // run self tests
|
|---|
| 83 | ERROR_PROPAGATE(self_test());
|
|---|
| 84 |
|
|---|
| 85 | // start the networking service
|
|---|
| 86 | if(! spawn("/srv/net")){
|
|---|
| 87 | fprintf(stderr, "Could not spawn net\n");
|
|---|
| 88 | return EINVAL;
|
|---|
| 89 | }
|
|---|
| 90 |
|
|---|
| 91 | // start the networking
|
|---|
| 92 | net_phone = connect_to_service(SERVICE_NETWORKING);
|
|---|
| 93 | if(ERROR_OCCURRED(ipc_call_sync_0_0(net_phone, NET_NET_STARTUP))){
|
|---|
| 94 | printf("ERROR %d\n", ERROR_CODE);
|
|---|
| 95 | return ERROR_CODE;
|
|---|
| 96 | }else{
|
|---|
| 97 | printf("OK\n");
|
|---|
| 98 | }
|
|---|
| 99 |
|
|---|
| 100 | return EOK;
|
|---|
| 101 | }
|
|---|
| 102 |
|
|---|
| 103 | task_id_t spawn(const char * fname){
|
|---|
| 104 | const char * argv[2];
|
|---|
| 105 | task_id_t res;
|
|---|
| 106 |
|
|---|
| 107 | argv[0] = fname;
|
|---|
| 108 | argv[1] = NULL;
|
|---|
| 109 | res = task_spawn(fname, argv);
|
|---|
| 110 |
|
|---|
| 111 | return res;
|
|---|
| 112 | }
|
|---|
| 113 |
|
|---|
| 114 | /** @}
|
|---|
| 115 | */
|
|---|