/[dtapublic]/projs/dtats/trunk/projs/2018/20180707_cgi_web_tools/active/ucspecific/nxp/mpc5748g/utestcensorshipsetsrec/index.php
ViewVC logotype

Contents of /projs/dtats/trunk/projs/2018/20180707_cgi_web_tools/active/ucspecific/nxp/mpc5748g/utestcensorshipsetsrec/index.php

Parent Directory Parent Directory | Revision Log Revision Log


Revision 169 - (show annotations) (download)
Sun Jul 8 16:25:59 2018 UTC (6 years, 5 months ago) by dashley
File size: 24339 byte(s)
Add initial port of CGI-BIN utilities.
1 <?php
2 require_once("style/std/stdwpstyle.inc");
3 //----------------------------------------------------------------------------------------------------
4 //This program calculates an S-record file that can be used to append to the UTEST area of the NXP MPC
5 //5748G and will disable censorship. This program is provided by David T. Ashley (dashley@gmail.com)
6 //under the MIT License (reproduced immediately below).
7 //----------------------------------------------------------------------------------------------------
8 //Copyright (c) 2018 David T. Ashley.
9 //
10 //Permission is hereby granted, free of charge, to any person obtaining a copy
11 //of this software and associated documentation files (the "Software"), to deal
12 //in the Software without restriction, including without limitation the rights
13 //to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14 //copies of the Software, and to permit persons to whom the Software is
15 //furnished to do so, subject to the following conditions:
16 //
17 //The above copyright notice and this permission notice shall be included in all
18 //copies or substantial portions of the Software.
19 //
20 //THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 //IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 //FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23 //AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24 //LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25 //OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26 //SOFTWARE.
27 //----------------------------------------------------------------------------------------------------
28 //Note to self: On 7/3/2018, I wrote Richard Stallman to inquire about what I should put in CGI
29 // output to protect myself from liability (like all software, CGI-BIN programs
30 // can contain bugs). If I don't hear back from Mr. Stallman within a a few weeks,
31 // I will have to take my best guess.
32 //----------------------------------------------------------------------------------------------------
33 //This program processes the following GET/POST parameters (GET and POST are treated identically):
34 // mode
35 // 0 or not defined 0
36 // Display the basic screen with choices of what to do.
37 // 1
38 // Display full instructions about how to modify the UTEST area to enable censorship.
39 // 2
40 // Calculate the correct S-record to modify UTEST.
41 // 3
42 // View the source code for this program.
43 // 4
44 // Provide feedback (a bit of a gag).
45 // addrhex
46 // A hexadecimal string specifying the starting address at which the UTEST programming should
47 // be done. Leading 0's will be removed, and lower-case and upper-case letters are treated
48 // identically. An empty string, a string containing unrecognized characters, or a string
49 // specifying a value outside [0, 2^32-256] will result in an error message. (By the way,
50 // the "256" margin is to avoid any part of the S-record specification exceeding [0, 2^32-1].
51 //----------------------------------------------------------------------------------------------------
52
53 function home_link_paragraph()
54 {
55 echo "<p align=\"center\">\n";
56 echo " Click <a href=\"index.php\">here</a> to return to the home choices screen.\n";
57 echo "</p>\n";
58 }
59
60 function screen_bad_mode($in_page_title)
61 {
62 $thispage = new StdWpStyle();
63
64 $thispage->static_page_header_title_std($in_page_title,
65 $in_page_title,
66 "");
67
68 echo "<p align=\"center\">\n";
69 echo " The <i>mode</i> HTTP POST/GET parameter was invalid.\n";
70 echo "</p>";
71
72 $thispage->static_page_hrule_std();
73
74 home_link_paragraph();
75
76 $thispage->static_page_footer_std();
77 }
78
79 function screen_bad_addr($in_page_title)
80 {
81 $thispage = new StdWpStyle();
82
83 $thispage->static_page_header_title_std($in_page_title,
84 $in_page_title,
85 "");
86
87 echo "<p align=\"center\">\n";
88 echo " The <i>addr</i> HTTP POST/GET parameter was invalid.\n";
89 echo "</p>";
90
91 $thispage->static_page_hrule_std();
92
93 home_link_paragraph();
94
95 $thispage->static_page_footer_std();
96 }
97
98 function screen_select($in_page_title)
99 {
100 $thispage = new StdWpStyle();
101
102 $thispage->static_page_header_title_std($in_page_title,
103 $in_page_title,
104 "");
105
106 echo "<p>\n";
107 echo "<form action=\"index.php\">\n";
108 echo "<input type=\"radio\" name=\"mode\" value=\"0\" checked>&nbsp;Display available choices (this screen).<br>\n";
109 echo "<input type=\"radio\" name=\"mode\" value=\"1\">&nbsp;Display full instructions for Clearing PASS_LCSTAT.CNS.<br>\n";
110 echo "<input type=\"radio\" name=\"mode\" value=\"2\">&nbsp;Calculate an S-record File to Add a DCF Record\n";
111 echo "to the UTEST Area Starting at Address\n";
112 echo "0x<input type=\"text\" name=\"addr\" value=\"0\"> in Order to Clear PASS_LCSTAT.CNS.<br>\n";
113 echo "<input type=\"radio\" name=\"mode\" value=\"3\">&nbsp;Display the source code for this page.<br>\n";
114 echo "<input type=\"radio\" name=\"mode\" value=\"4\">&nbsp;Provide feedback on this page.<br><br>\n";
115 echo "<input type=\"submit\" value=\"Take Action Specified Above ...\">\n";
116 echo "</form>\n";
117 echo "</p>";
118
119 $thispage->static_page_footer_std();
120 }
121
122 function screen_instructions($in_page_title)
123 {
124 $preamble = array
125 (
126 "<p>",
127 "This page contains the instructions for clearing the PASS_LCSTAT.CNS bit, which is one",
128 "prerequisite for the GHS probe working correctly across low-power modes.",
129 "</p>"
130 );
131
132 $step01 = array
133 (
134 "<p>",
135 "<b><u>Step 1: Install the Latest GHS Tools</u></b>",
136 "</p>",
137 "<p>",
138 "Tool updates are typically made available by GHS in the form of ISO images",
139 "that can be downloaded from the GHS support website (<i>support.ghs.com</i>, screen",
140 "snapsot below).&nbsp; A valid license and login are required.",
141 "</p>",
142 "<p align=\"center\">",
143 "<img src=\"comp_2018_1_4_final_release.png\">",
144 "</p>",
145 "<p>",
146 "Once a DVD has been produced from the ISO image, three installations are typically",
147 "required&mdash;the compiler, the debugger, and the license administrator.&nbsp;",
148 "Typically, so that different versions of the same tool can coexist and so that",
149 "all developers on a team have tools in exactly the same place, there is a",
150 "local policy about the exact paths that must be used for installation.",
151 "</p>"
152 );
153
154 $step02 = array
155 (
156 "<p>",
157 "<b><u>Step 2: Re-FLASH the GHS Probe</u></b>",
158 "</p>",
159 "<p>",
160 "After the newest version of the GHS software has been installed (Step 1, above), the most recent",
161 "GHS Probe firmware should be in a <i>.frm</i> file in the compiler installation directory.&nbsp;",
162 "Use the Probe Administrator to re-FLASH the GHS Probe with this firmware.",
163 "</p>",
164 "<p>",
165 "Verify that the correct updated firmware has been FLASH'd using the <i>target support</i>",
166 "command from within the debugger. As of this writing, the expected information would be:",
167 "</p>",
168 "<p>",
169 "<pre>",
170 "MULTI&gt; target support",
171 "*************************** Firmware Info ****************************",
172 "",
173 "Probe Firmware Release Version 5.6.4",
174 "</pre>",
175 "</p>"
176 );
177
178 $step03 = array
179 (
180 "<p>",
181 "<b><u>Step 3: Check that PASS_LCSTAT[CNS] is 1</u></b>",
182 "</p>",
183 "<p>",
184 "(If it isn't 1, there is no need to write a new DCF record.)",
185 "</p>",
186 "<p>",
187 "Using the debugger, run the application software for a second or two and stop it",
188 "(all that matters is that the part has made it out of reset).",
189 "</p>",
190 "<p align=\"center\">",
191 "<img src=\"pass_lcstat_in_debugger_value_1.png\">",
192 "</p>",
193 "<p>",
194 "The debugger output with CNS == 1 is shown above. If CNS == 1, you have to",
195 "write a new DCF record. If CNS == 0, you can skip all other steps in this e-mail.",
196 "</p>"
197 );
198
199 $step04 = array
200 (
201 "<p>",
202 "<b><u>Step 4: Identify the Address Where the New DCR Record Should Be Written</u></b>",
203 "</p>",
204 "<p>",
205 "This step is necessary because not all modules are guaranteed to have the",
206 "same number of DCF records.&nbsp; Because DCF records can only be appended,",
207 "the address at which a write is required may vary from module to module.",
208 "</p>",
209 "<p>",
210 "The DCF records, each one 64 bits, are processed by the hardware as part",
211 "of the RESET process.&nbsp; It is a linear search through FLASH, ending when",
212 "a record is found where the least significant bit is 1 (which would be the",
213 "case with erased FLASH).",
214 "</p>",
215 "<p>",
216 "You are not free to write the DCF record anywhere (because of the linear",
217 "search, you must append it to the last valid DCF record).&nbsp; Also, the",
218 "hardware won't allow you to erase existing DCF records&mdash;you can only",
219 "append by programming.&nbsp; DCF record programming mistakes can often be",
220 "corrected by adding another DCF record writing a register to a different",
221 "value (but this is not universally true for all registers).",
222 "</p>",
223 "<p>",
224 "From Table 3-3 in the reference manual:",
225 "</p>",
226 "<p align=\"center\">",
227 "<img src=\"rm_table_3_3.png\">",
228 "</p>",
229 "<p>",
230 "The start address at which you need to write the new DCF record will be",
231 "DWORD aligned (address will be a multiple of 8), and somewhere in the range",
232 "of 0x00400348 through 0x00400FF8.",
233 "</p>",
234 "<p>",
235 "Using a debugger, examine the UTEST area to find the first 0xFFFFFFFF",
236 "(unprogrammed) location.",
237 "</p>",
238 "<p>",
239 "The image below is the UTEST FLASH contents before I programmed the new",
240 "DCF record.&nbsp; You can see that 0x400638 is the location at which the new",
241 "DCF record must be written.",
242 "</p>",
243 "<p align=\"center\">",
244 "<img src=\"utest_flash_before.png\">",
245 "</p>"
246 );
247
248 $step05 = array
249 (
250 "<p>",
251 "<b><u>Step 5: Prepare an S-Record File Specifying the New DCF Record</u></b>",
252 "</p>",
253 "<p>",
254 "The S-Record file I prepared is this one:",
255 "</p>",
256 "<p>",
257 "<pre>",
258 "S011000000486578766965772056312E3039D0",
259 "S20C400638000055AA001000B0B6",
260 "S804FFFFFFFE",
261 "</pre>",
262 "</p>",
263 "<p>",
264 "Note that the address to write is embedded in the S19 file,",
265 "<i>400638</i>.&nbsp; (That is why the S19 file you have to use may be different than the",
266 "example provided above.)",
267 "</p>",
268 "<p>",
269 "The bytes to write must be, in order:",
270 "</p>",
271 "<p>",
272 "<pre>",
273 "00 00 55 AA 00 10 00 B0",
274 "</pre>",
275 "</p>",
276 "<p>",
277 "These set <i>Censorship</i> to <i>Uncensored</i>.",
278 "</p>",
279 "<p>",
280 "This set of web pages provides a web-based calculator that can be used",
281 "to calculate an appropriate S19 file.",
282 "</p>",
283 "<p>",
284 "Although it can easily be done, I don't recommend &quot;hand-rolling&quot; an S19 file",
285 "(for example, by editing the text above).&nbsp; The issue is that there is a checksum at",
286 "the end, and I don't know for sure how the GHS tools will react if that is invalid",
287 "(an invalid checksum would be a natural mistake when preparing an S19 manually).",
288 "</p>",
289 "<p>",
290 "Double-check the S19 file to be sure that it covers only the addresses",
291 "you wish to program.&nbsp; In my S19 file:",
292 "</p>",
293 "<p>",
294 "<pre>",
295 "S20C 400638 <b><u>000055AA001000B0</u></b> B6",
296 "</pre>",
297 "</p>",
298 "<p>",
299 "the payload is underlined.&nbsp; If there are more or less than 8 bytes",
300 "specified, you've done something wrong.&nbsp; Also, if the last digit of the address is",
301 "not a 0 or an 8, you've done something wrong.",
302 "</p>"
303 );
304
305
306 $step06 = array
307 (
308 "<p>",
309 "<b><u>Step 6: Program the UTEST Area</u></b>",
310 "</p>",
311 "<p>",
312 "The instructions below were provided by a GHS employee.&nbsp; I've reproduced them verbatim (in <i>italics</i>).",
313 "</p>",
314 "<p><i>",
315 "DCFs are 64 bits, and are evaluated by the CPU in order until an invalid record is found.&nbsp; Changing",
316 "CNS requires a single new DCF entry at the end of the list.&nbsp; Our flashing tools are somewhat",
317 "big for this use case of programming only a few words at a time. Some options for programming",
318 "are (in no particular order):",
319 "<ul>",
320 "<li>",
321 "Use the flash programming GUI. This requires one of:",
322 "<ul>",
323 "<li>",
324 "(a) A raw binary file, OR",
325 "</li>",
326 "<li>",
327 "(b) an SREC file containing the new DCF record.",
328 "</li>",
329 "</ul>",
330 "</li>",
331 "</ul>",
332 "</p>",
333 "<p>",
334 "The programming address must be the next empty DCF slot in UTEST for",
335 "(a) this is specified in the flash GUI; for (b) the address is built",
336 "in to the SREC format.&nbsp; You must select a <i>.mbs</i> that allows",
337 "downloading to and running code from RAM.&nbsp; All the usual flash GUI",
338 "parameters must be set, with an additional",
339 "&amp;modify_utest=1 appended to the flash bank parameter to allow u-test access.",
340 "</i>",
341 "</p>",
342 "<p>",
343 "The screenshot below shows the choices that I made in the FLASH programming GUI",
344 "that I made per GHS instructions.&nbsp; Changes from normal program FLASH programming:&nbsp;",
345 "(a) Addition of &amp;modify_utest=1,",
346 "(b) custom S-record file specified, and (c) <i>Erase</i> unchecked.",
347 "</p>",
348 "<p align=\"center\">",
349 "<img src=\"flash_programming.png\">",
350 "</p>",
351 "<p>",
352 "When programming the FLASH, there should be no error messages.",
353 "</p>"
354 );
355
356 $step07 = array
357 (
358 "<p>",
359 "<b><u>Step 7: Verify the UTEST Program Operation</u></b>",
360 "</p>",
361 "<p>",
362 "Run the application under the debugger and examine memory.&nbsp; In my case (screenshot below), the program",
363 "at 0x400638 was successful.",
364 "<p align=\"center\">",
365 "<img src=\"utest_after_programming.png\">",
366 "</p>"
367 );
368
369 $step08 = array
370 (
371 "<p>",
372 "<b><u>Step 8: Verify that PASS_LCSTAT[CNS] is 0</u></b>",
373 "</p>",
374 "<p>",
375 "Run the application, stop it and examine the PASS module. Below, CNS is 0, which is the desired outcome.",
376 "</p>",
377 "<p align=\"center\">",
378 "<img src=\"pass_lcstat_in_debugger.png\">",
379 "</p>",
380 "<p>",
381 "Debugging through STANDBY and STOP should now work.",
382 "</p>"
383 );
384
385 $full_instructions = array
386 (
387 $preamble,
388 $step01,
389 $step02,
390 $step03,
391 $step04,
392 $step05,
393 $step06,
394 $step07,
395 $step08
396 );
397
398 $thispage = new StdWpStyle();
399
400 $thispage->static_page_header_title_std($in_page_title,
401 $in_page_title,
402 "");
403
404 //For each group of content.
405 for ($i = 0; $i < count($full_instructions); $i++)
406 {
407 $group = $full_instructions[$i];
408
409 //For each line in the content.
410 for ($j = 0; $j < count($group); $j++)
411 {
412 echo $group[$j] . "\n";
413 }
414
415 $thispage->static_page_hrule_std();
416 }
417
418 home_link_paragraph();
419
420 $thispage->static_page_footer_std();
421 }
422
423 function screen_s_record($in_page_title, $in_addr_array)
424 {
425 $thispage = new StdWpStyle();
426
427 $thispage->static_page_header_title_std($in_page_title,
428 $in_page_title,
429 "");
430
431 echo "<p align=\"center\">\n";
432 echo "The S-record file to program the DCF record at address 0x"
433 . sprintf("%02X%02X%02X%02X", $in_addr_array[0], $in_addr_array[1], $in_addr_array[2], $in_addr_array[3]) .
434 " is below.&nbsp;\n";
435 echo "This can be pasted into an appropriate programming tool.\n";
436 echo "</p>";
437
438 $thispage->static_page_hrule_std();
439
440 echo "<pre>\n";
441
442 //The first line, I believe, can be left as a constant.
443 echo "S011000000486578766965772056312E3039D0\n";
444
445 //The second line is more complex.
446 $checksum = 0;
447 $payload = array(0x00, 0x00, 0x55, 0xAA, 0x00, 0x10, 0x00, 0xB0);
448
449 if (($in_addr_array[0] == 0) && ($in_addr_array[1] == 0))
450 {
451 //S1 record, 2-byte address.
452 echo "S1";
453 $count = 2 + count($payload) + 1;
454 echo sprintf("%02X", $count);
455 $checksum += $count;
456 echo sprintf("%02X", $in_addr_array[2]);
457 $checksum += $in_addr_array[2];
458 echo sprintf("%02X", $in_addr_array[3]);
459 $checksum += $in_addr_array[3];
460 }
461 else if ($in_addr_array[0] == 0)
462 {
463 //S2 record, 3-byte address.
464 echo "S2";
465 $count = 3 + count($payload) + 1;
466 echo sprintf("%02X", $count);
467 $checksum += $count;
468 echo sprintf("%02X", $in_addr_array[1]);
469 $checksum += $in_addr_array[1];
470 echo sprintf("%02X", $in_addr_array[2]);
471 $checksum += $in_addr_array[2];
472 echo sprintf("%02X", $in_addr_array[3]);
473 $checksum += $in_addr_array[3];
474 }
475 else
476 {
477 //S3 record, 3-byte address.
478 echo "S3";
479 $count = 4 + count($payload) + 1;
480 echo sprintf("%02X", $count);
481 $checksum += $count;
482 echo sprintf("%02X", $in_addr_array[0]);
483 $checksum += $in_addr_array[0];
484 echo sprintf("%02X", $in_addr_array[1]);
485 $checksum += $in_addr_array[1];
486 echo sprintf("%02X", $in_addr_array[2]);
487 $checksum += $in_addr_array[2];
488 echo sprintf("%02X", $in_addr_array[3]);
489 $checksum += $in_addr_array[3];
490 }
491
492 //Emit the payload bytes, maintaining the checksum.
493 for ($i=0; $i<count($payload); $i++)
494 {
495 echo sprintf("%02X", $payload[$i]);
496 $checksum += $payload[$i];
497 }
498
499 //Adjust the checksum. Because integers in PHP are 32-bit signed,
500 //I need to be careful how I calculate the 1's complement, so as not
501 //to create a negative number.
502 $checksum %= 256; //Checksum now in [0, 255].
503 $checksum = 255 - $checksum; //Checksum still in [0, 255].
504
505 //Emit the checksum.
506 echo sprintf("%02X", $checksum);
507
508 echo "\n";
509 //echo "S20C400638000055AA001000B0B6\n";
510
511 //The last line, I believe, can be left as a constant.
512 echo "S804FFFFFFFE\n";
513
514 echo "</pre>\n";
515
516 $thispage->static_page_hrule_std();
517
518 home_link_paragraph();
519
520 $thispage->static_page_footer_std();
521 }
522
523 function screen_source($in_page_title)
524 {
525 $thispage = new StdWpStyle();
526
527 $thispage->static_page_header_title_std($in_page_title,
528 $in_page_title,
529 "");
530
531 echo "<p align=\"center\">\n";
532 echo "The page source code is provided below.\n";
533 echo "</p>";
534
535 $thispage->static_page_hrule_std();
536
537 echo "<pre>\n";
538
539 $source_file_contents = file("index.php");
540
541 for ($i=0; $i<count($source_file_contents); $i++)
542 {
543 $line = $source_file_contents[$i];
544
545 if (strlen($line) > 0)
546 {
547 if (substr($line, strlen($line)-1, 1) == "\n")
548 {
549 $line = substr($line, 0, strlen($line)-1);
550 }
551 else
552 {
553 }
554
555 echo htmlspecialchars($line) . "\n";
556 }
557 else
558 {
559 echo "\n";
560 }
561 }
562
563 echo "</pre>\n";
564
565 $thispage->static_page_hrule_std();
566
567 home_link_paragraph();
568
569 $thispage->static_page_footer_std();
570 }
571
572 function screen_feedback($in_page_title)
573 {
574 $thispage = new StdWpStyle();
575
576 $thispage->static_page_header_title_std($in_page_title,
577 $in_page_title,
578 "");
579
580 echo "<p align=\"center\">\n";
581 echo "I do not care about your opinion.&nbsp; Keep your feedback to yourself, and do not trouble me with it.\n";
582 echo "</p>";
583
584 $thispage->static_page_hrule_std();
585
586 home_link_paragraph();
587
588 $thispage->static_page_footer_std();
589 }
590
591 //Output HTTP header info before any other output. This should
592 //hopefully prevent any browser or proxy caching.
593 header("Expires: Tue, 03 Jul 2001 06:00:00 GMT");
594 header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
595 header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
596 header("Cache-Control: post-check=0, pre-check=0", false);
597 header("Pragma: no-cache");
598 header("Connection: close");
599
600 //Constants, not quite properly declared.
601 $page_title = "NXP MPC5748G PASS_LCSTAT.CNS-Clearing UTEST DCF Record S-Record Generation Utility";
602
603 //Start off believing no errors. Parameters are normalized. Errors are a
604 //different matter.
605 $error_bad_mode = False;
606 $error_bad_addr = False;
607 $status_mode_found = False;
608 $status_addr_found = False;
609
610 //Set the $in_mode parameter based on POST/GET input. POST gets preference.
611 if (isset($_POST['mode']))
612 {
613 $in_mode = $_POST['mode'];
614 $status_mode_found = True;
615 }
616 else if (isset($_GET['mode']))
617 {
618 $in_mode = $_GET['mode'];
619 $status_mode_found = True;
620 }
621 else
622 {
623 $in_mode = "0";
624 }
625
626 //Normalize $in_mode to be an integer [0, 4]. Anything unrecognized
627 //gets the value 0 and is an error.
628 if (is_numeric($in_mode))
629 {
630 $in_mode = (int)$in_mode;
631 }
632 else
633 {
634 $in_mode = 0;
635 $error_bad_mode = True;
636 }
637
638 if (($in_mode < 0) || ($in_mode > 4))
639 {
640 $in_mode = 0;
641 $error_bad_mode = True;
642 }
643
644 //Normalize addrhex. Because a PHP integer is a signed 32-bit integer (not large enough), normalize
645 //to be a string exactly 8 characters long, consisting of only digits and upper-case letters.
646 if (isset($_POST['addr']))
647 {
648 $in_addr = $_POST['addr'];
649 $status_addr_found = True;
650 }
651 else if (isset($_GET['addr']))
652 {
653 $in_addr = $_GET['addr'];
654 $status_addr_found = True;
655 }
656 else
657 {
658 $in_addr = "0";
659 }
660
661 //Trim the string of leading and trailing whitespace.
662 $in_addr = trim($in_addr);
663
664 //Trim any leading 0's, but leave the final character.
665 while ((strlen($in_addr) > 1) && (substr($in_addr, 0, 1) == "0"))
666 {
667 $in_addr = substr($in_addr, 1, strlen($in_addr)-1);
668 }
669
670 //If the string is the empty string, it is bogus.
671 if (strlen($in_addr) == 0)
672 {
673 $in_addr = "0";
674 $error_bad_addr = True;
675 }
676
677 //If it is less than 8 characters, left-pad it.
678 while (strlen($in_addr) < 8)
679 {
680 $in_addr = "0" . $in_addr;
681 }
682
683 //If the string is not 8 characters, it is bogus.
684 if (strlen($in_addr) != 8)
685 {
686 $in_addr = "00000000";
687 $error_bad_addr = True;
688 }
689
690 //Convert any lower-case letters to upper-case letters.
691 $in_addr = strtoupper($in_addr);
692
693 //Every character in the string at this point has to be in
694 //"0123456789ABCDEF" or the string is bogus.
695 for ($i=0; $i<strlen($in_addr); $i++)
696 {
697 $c = substr($in_addr, $i, 1);
698
699 if (strpos("0123456789ABCDEF", $c) === False)
700 {
701 $in_addr = "00000000";
702 $error_bad_addr = True;
703 break;
704 }
705 }
706
707 //Convert the character-based address to an array of 4
708 //bytes.
709 for ($i=0; $i<4; $i++)
710 {
711 $in_addr_array[$i] = strpos("0123456789ABCDEF", substr($in_addr, $i*2, 1)) * 16
712 + strpos("0123456789ABCDEF", substr($in_addr, $i*2+1, 1));
713 }
714
715 //Decide exactly what to do based on the parsed POST/GET parameters.
716 if ($error_bad_mode)
717 {
718 screen_bad_mode($page_title);
719 }
720 else if ($status_addr_found && $error_bad_addr)
721 {
722 screen_bad_addr($page_title);
723 }
724 else if ($in_mode == 0)
725 {
726 screen_select($page_title);
727 }
728 else if ($in_mode == 1)
729 {
730 screen_instructions($page_title);
731 }
732 else if ($in_mode == 2)
733 {
734 screen_s_record($page_title, $in_addr_array);
735 }
736 else if ($in_mode == 3)
737 {
738 screen_source($page_title);
739 }
740 else if ($in_mode == 4)
741 {
742 screen_feedback($page_title);
743 }
744 else
745 {
746 screen_bad_mode();
747 }
748 ?>

Properties

Name Value
svn:eol-style native
svn:keywords Header

dashley@gmail.com
ViewVC Help
Powered by ViewVC 1.1.25