Mercurial > ecos-v3_0-branch
annotate packages/net/ppp/current/tests/ppp_auth.c @ 2729:74dbf4c3f2e1 after-copyright-change-20090129
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
| author | jlarmour |
|---|---|
| date | Thu, 29 Jan 2009 17:47:46 +0000 |
| parents | e0d88dc6a92f |
| children |
| rev | line source |
|---|---|
| 1586 | 1 //========================================================================== |
| 2 // | |
| 3 // tests/ppp_auth.c | |
| 4 // | |
| 5 // Simple test of PPP authentication support | |
| 6 // | |
| 7 //========================================================================== | |
|
2729
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
1586
diff
changeset
|
8 // ####ECOSGPLCOPYRIGHTBEGIN#### |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
1586
diff
changeset
|
9 // ------------------------------------------- |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
1586
diff
changeset
|
10 // This file is part of eCos, the Embedded Configurable Operating System. |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
1586
diff
changeset
|
11 // Copyright (C) 2003 Free Software Foundation, Inc. |
| 1586 | 12 // |
|
2729
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
1586
diff
changeset
|
13 // eCos is free software; you can redistribute it and/or modify it under |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
1586
diff
changeset
|
14 // the terms of the GNU General Public License as published by the Free |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
1586
diff
changeset
|
15 // Software Foundation; either version 2 or (at your option) any later |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
1586
diff
changeset
|
16 // version. |
| 1586 | 17 // |
|
2729
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
1586
diff
changeset
|
18 // eCos is distributed in the hope that it will be useful, but WITHOUT |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
1586
diff
changeset
|
19 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
1586
diff
changeset
|
20 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
1586
diff
changeset
|
21 // for more details. |
| 1586 | 22 // |
|
2729
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
1586
diff
changeset
|
23 // You should have received a copy of the GNU General Public License |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
1586
diff
changeset
|
24 // along with eCos; if not, write to the Free Software Foundation, Inc., |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
1586
diff
changeset
|
25 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 1586 | 26 // |
|
2729
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
1586
diff
changeset
|
27 // As a special exception, if other files instantiate templates or use |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
1586
diff
changeset
|
28 // macros or inline functions from this file, or you compile this file |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
1586
diff
changeset
|
29 // and link it with other works to produce a work based on this file, |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
1586
diff
changeset
|
30 // this file does not by itself cause the resulting work to be covered by |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
1586
diff
changeset
|
31 // the GNU General Public License. However the source code for this file |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
1586
diff
changeset
|
32 // must still be made available in accordance with section (3) of the GNU |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
1586
diff
changeset
|
33 // General Public License v2. |
| 1586 | 34 // |
|
2729
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
1586
diff
changeset
|
35 // This exception does not invalidate any other reasons why a work based |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
1586
diff
changeset
|
36 // on this file might be covered by the GNU General Public License. |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
1586
diff
changeset
|
37 // ------------------------------------------- |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
1586
diff
changeset
|
38 // ####ECOSGPLCOPYRIGHTEND#### |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
1586
diff
changeset
|
39 // ####BSDALTCOPYRIGHTBEGIN#### |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
1586
diff
changeset
|
40 // ------------------------------------------- |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
1586
diff
changeset
|
41 // Portions of this software may have been derived from FreeBSD, OpenBSD, |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
1586
diff
changeset
|
42 // or other sources, and if so are covered by the appropriate copyright |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
1586
diff
changeset
|
43 // and license included herein. |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
1586
diff
changeset
|
44 // ------------------------------------------- |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
1586
diff
changeset
|
45 // ####BSDALTCOPYRIGHTEND#### |
| 1586 | 46 //========================================================================== |
| 47 //#####DESCRIPTIONBEGIN#### | |
| 48 // | |
| 49 // Author(s): nickg | |
| 50 // Contributors: nickg | |
| 51 // Date: 2003-06-01 | |
| 52 // Purpose: | |
| 53 // Description: This test just brings the PPP link up and waits for the | |
| 54 // other end to bring it down. Meanwhile the other end can | |
| 55 // ping us, or talk to the HTTPD if it is configured. | |
| 56 // | |
| 57 // | |
| 58 //####DESCRIPTIONEND#### | |
| 59 // | |
| 60 //========================================================================== | |
| 61 | |
| 62 // PPP test code | |
| 63 | |
| 64 #include "ppp_test_support.inl" | |
| 65 | |
| 66 //========================================================================== | |
| 67 | |
| 68 typedef void pr_fun(char *fmt, ...); | |
| 69 | |
| 70 externC void show_network_tables(pr_fun *pr); | |
| 71 | |
| 72 //========================================================================== | |
| 73 | |
| 74 | |
| 75 #ifndef CYGPKG_LIBC_STDIO | |
| 76 #define perror(s) diag_printf(#s ": %s\n", strerror(errno)) | |
| 77 #endif | |
| 78 | |
| 79 #define STACK_SIZE (CYGNUM_HAL_STACK_SIZE_TYPICAL + 0x1000) | |
| 80 static char stack[STACK_SIZE]; | |
| 81 static cyg_thread thread_data; | |
| 82 static cyg_handle_t thread_handle; | |
| 83 | |
| 84 //========================================================================== | |
| 85 // Tests | |
| 86 // | |
| 87 // The following table contains parameters for various tests permuting | |
| 88 // the authentication requirements of the peer, the authentication | |
| 89 // requirements of this end and the user name and password used. | |
| 90 // | |
| 91 // For this test to work the /etc/ppp/pap-secrets file on the remote | |
| 92 // end should contain the following two lines: | |
| 93 // | |
| 94 // eCos * secret * | |
| 95 // eCosPAP * secretPAP * | |
| 96 // | |
| 97 // The /etc/ppp/chap-secrets file should contain: | |
| 98 // | |
| 99 // eCos * secret * | |
| 100 // eCosCHAP * secretCHAP * | |
| 101 // | |
| 102 | |
| 103 static struct auth_info | |
| 104 { | |
| 105 char *name; | |
| 106 cyg_serial_baud_rate_t baud; | |
| 107 int refuse_pap; | |
| 108 int refuse_chap; | |
| 109 char user[MAXNAMELEN]; | |
| 110 char passwd[MAXSECRETLEN]; | |
| 111 cyg_int32 result; | |
| 112 } tests[] = | |
| 113 { | |
| 114 // PPP_AUTH_1 just tries the default auth mechanism for the server | |
| 115 { "PPP_AUTH_1", CYGNUM_SERIAL_BAUD_115200, 0, 0, "eCos", "secret", 0 }, | |
| 116 { "PPP_AUTH_1", CYGNUM_SERIAL_BAUD_115200, 0, 0, "eCos", "secretX", -1 }, | |
| 117 { "PPP_AUTH_1", CYGNUM_SERIAL_BAUD_115200, 0, 0, "eCosX", "secret", -1 }, | |
| 118 | |
| 119 // PPP_AUTH_2 requires PAP authentication only | |
| 120 { "PPP_AUTH_2", CYGNUM_SERIAL_BAUD_115200, 1, 0, "eCosCHAP", "secretCHAP", -1 }, | |
| 121 { "PPP_AUTH_2", CYGNUM_SERIAL_BAUD_115200, 1, 0, "eCosPAP", "secretPAP", -1 }, | |
| 122 { "PPP_AUTH_2", CYGNUM_SERIAL_BAUD_115200, 1, 0, "eCos", "secret", -1 }, | |
| 123 { "PPP_AUTH_2", CYGNUM_SERIAL_BAUD_115200, 0, 1, "eCosCHAP", "secretCHAP", -1 }, | |
| 124 { "PPP_AUTH_2", CYGNUM_SERIAL_BAUD_115200, 0, 1, "eCosPAP", "secretPAP", 0 }, | |
| 125 { "PPP_AUTH_2", CYGNUM_SERIAL_BAUD_115200, 0, 1, "eCos", "secret", 0 }, | |
| 126 | |
| 127 // PPP_AUTH_3 requires CHAP authentication only | |
| 128 { "PPP_AUTH_3", CYGNUM_SERIAL_BAUD_115200, 0, 1, "eCosPAP", "secretPAP", -1 }, | |
| 129 { "PPP_AUTH_3", CYGNUM_SERIAL_BAUD_115200, 0, 1, "eCosCHAP", "secretCHAP", -1 }, | |
| 130 { "PPP_AUTH_3", CYGNUM_SERIAL_BAUD_115200, 0, 1, "eCos", "secret", -1 }, | |
| 131 { "PPP_AUTH_3", CYGNUM_SERIAL_BAUD_115200, 1, 0, "eCosPAP", "secretPAP", -1 }, | |
| 132 { "PPP_AUTH_3", CYGNUM_SERIAL_BAUD_115200, 1, 0, "eCosCHAP", "secretCHAP", 0 }, | |
| 133 { "PPP_AUTH_3", CYGNUM_SERIAL_BAUD_115200, 1, 0, "eCos", "secret", 0 }, | |
| 134 | |
| 135 { NULL } | |
| 136 }; | |
| 137 | |
| 138 //========================================================================== | |
| 139 | |
| 140 | |
| 141 static int do_test( struct auth_info *test ) | |
| 142 { | |
| 143 cyg_ppp_options_t options; | |
| 144 cyg_ppp_handle_t ppp_handle; | |
| 145 int i = 0; | |
| 146 cyg_int32 result; | |
| 147 | |
| 148 CYG_TEST_INFO( test->name ); | |
| 149 | |
| 150 ppp_test_set_baud( test->baud ); | |
| 151 | |
| 152 ppp_test_announce( test->name ); | |
| 153 | |
| 154 cyg_ppp_options_init( &options ); | |
| 155 | |
| 156 // options.debug = 1; | |
| 157 // options.kdebugflag = 1; | |
| 158 | |
| 159 options.baud = test->baud; | |
| 160 options.refuse_pap = test->refuse_pap; | |
| 161 options.refuse_chap = test->refuse_chap; | |
| 162 strncpy( options.user, test->user, MAXNAMELEN ); | |
| 163 strncpy( options.passwd, test->passwd, MAXNAMELEN ); | |
| 164 | |
| 165 // show_network_tables( diag_printf ); | |
| 166 | |
| 167 ppp_handle = cyg_ppp_up( CYGPKG_PPP_TEST_DEVICE, &options ); | |
| 168 | |
| 169 CYG_TEST_INFO( "Waiting for PPP to come up"); | |
| 170 | |
| 171 result = cyg_ppp_wait_up( ppp_handle ); | |
| 172 | |
| 173 if( result != test->result ) | |
| 174 { | |
| 175 CYG_TEST_INFO( "Failed" ); | |
| 176 | |
| 177 return 0; | |
| 178 } | |
| 179 else | |
| 180 { | |
| 181 CYG_TEST_INFO( "Waiting until remote end goes down"); | |
| 182 | |
| 183 while( cyg_ppp_wait_up( ppp_handle ) == 0 ) | |
| 184 { | |
| 185 i++; | |
| 186 | |
| 187 // if( (i % 60) == 0 ) | |
| 188 // show_network_tables( diag_printf ); | |
| 189 | |
| 190 cyg_thread_delay(100); | |
| 191 } | |
| 192 | |
| 193 cyg_ppp_wait_down( ppp_handle ); | |
| 194 | |
| 195 return 1; | |
| 196 } | |
| 197 | |
| 198 } | |
| 199 | |
| 200 //========================================================================== | |
| 201 | |
| 202 void | |
| 203 ppp_test(cyg_addrword_t p) | |
| 204 { | |
| 205 cyg_serial_baud_rate_t old; | |
| 206 struct auth_info *test; | |
| 207 int failures = 0; | |
| 208 | |
| 209 CYG_TEST_INIT(); | |
| 210 diag_printf("Start PPP test\n"); | |
| 211 | |
| 212 init_all_network_interfaces(); | |
| 213 | |
| 214 old = ppp_test_set_baud( CYGNUM_SERIAL_BAUD_38400 ); | |
| 215 | |
| 216 | |
| 217 for( test = &tests[0]; test->name != NULL; test++ ) | |
| 218 { | |
| 219 if( !do_test( test ) ) | |
| 220 failures++; | |
| 221 | |
| 222 cyg_thread_delay(300); | |
| 223 } | |
| 224 | |
| 225 ppp_test_set_baud( old ); | |
| 226 | |
| 227 ppp_test_finish(); | |
| 228 | |
| 229 if( failures > 0 ) | |
| 230 CYG_TEST_FAIL("Some tests failed"); | |
| 231 else | |
| 232 CYG_TEST_PASS("OK"); | |
| 233 | |
| 234 CYG_TEST_FINISH("PPP auth test"); | |
| 235 } | |
| 236 | |
| 237 //========================================================================== | |
| 238 | |
| 239 void | |
| 240 cyg_start(void) | |
| 241 { | |
| 242 // Create a main thread, so we can run the scheduler and have time 'pass' | |
| 243 cyg_thread_create(10, // Priority - just a number | |
| 244 ppp_test, // entry | |
| 245 0, // entry parameter | |
| 246 "PPP test", // Name | |
| 247 &stack[0], // Stack | |
| 248 STACK_SIZE, // Size | |
| 249 &thread_handle, // Handle | |
| 250 &thread_data // Thread data structure | |
| 251 ); | |
| 252 cyg_thread_resume(thread_handle); // Start it | |
| 253 cyg_scheduler_start(); | |
| 254 } | |
| 255 | |
| 256 //========================================================================== |
