| |
swebled.pwp
//-------------------------------------------------------------------------
//
// PicoWeb Project File for sWebLED (WebLED with passwords)
//
//-------------------------------------------------------------------------
//
// application-specific preprocessor definitions
//
#define BANNER "\r\nSecure PicoWeb WebLED\r\n"
#define NET_CONFIG_IP /* allow IP address reconfiguration via net */
#define ENABLE_WATCHDOG /* use Atmel watchdog timer hardware */
#define DEBUGGER /* include debugger firmware */
//#define CLOCK 8000000
#define CLOCK 7372000
#define BAUD_RATE 19200
//#define PASSWORD_IN_SEEPROM
//
// application-specific HTML and image file names
//
swebled.htm // default Web page
bruce.jpg
dave.jpg
steve.jpg
warning.gif
//
// public application-specific CGI routines (for testing only!)
//
pshow_password.cgi // print password from URL
pshow_real_password.cgi // print password stored in (S)EEPROM
pset_password.cgi // set passowrd in (S)EEPROM with one from URL
//
// included application-specific pcode and/or AVR assembly language follows
//
#avr_reset
;--------------------------------------------------------------------------
; this code is executed each time microcontroller is reset
;--------------------------------------------------------------------------
;
sbi ddrd,LED_BIT ; make LED driver pin an output
#avr_slow
;--------------------------------------------------------------------------
; this code is executed each trip through "slow idle" loop (~1 sec period)
;--------------------------------------------------------------------------
;
#avr_fast
;--------------------------------------------------------------------------
; this code is executed each trip through "fast idle" loop
;--------------------------------------------------------------------------
;
#avr_asm
;--------------------------------------------------------------------------
; application-specific CGI pcode and AVR assembly routines go here
;--------------------------------------------------------------------------
;
;--------------------------------------------------------------------------
;
; CGI routines for password checking/setting
;
; These pcode routines all operate by scanning for the string PWD_CMD in
; the URL (see #define PWD_CMD below). The logic below assumes that the
; password strings are exactly NUM_PASSWORD_CHARS characters in length
; and consists entirely of characters and/or digits. Javascript validation
; might be used in Web pages to ensure this is the case.
;
; pno_password - sets Z flag if no PWD_CMD parameter in URL.
; Routine can be used with PicoWeb HTML
; `?xxx.cgi?0`<pw_if>...<pw_else>...<pw_endif>
; tags.
;
; pchk_password - sets Z flag if either the password string
; supplied in the URL is wrong, or if there
; is no PWD_CMD parameter is supplied.
; Routine can be used with PicoWeb HTML
; `?xxx.cgi?0`<pw_if>...<pw_else>...<pw_endif>
; tags.
;
; pshow_password - prints password string from URL PWD_CMD
; parameter.
;
; pshow_real_password - prints password string stored in (S)EEPROM.
;
; pset_password - sets password string in (S)EEPROM to string
; supplied with URL PWD_CMD parameter. Use of
; this routine in a Web page should probably be
; protected in some way (i.e., with old password).
;
;--------------------------------------------------------------------------
#define PWD_CMD "PW=" /* define URL password parameter */
#ifdef PASSWORD_IN_SEEPROM
.section seeprom
#else
.section eeprom
#endif
#define NUM_PASSWORD_CHARS 8
password: ; exactly 8 characters (must be blank padded, null terminated)
.byte '1','2','3','4','5','6','7','8',0
#ifdef PASSWORD_IN_SEEPROM
.align 1 ; needed if you want pcode in SEEPROM to still work!
#endif
.eseg
#define PPWBUF buf+2
#define PWCNT buf+4
#define PWCH buf+6
#define PWCH2 buf+7
#define PWBUF buf+8
pno_password:
purlparm buf,PWD_CMD ; search for password parameter
pjumpne ok_password
pjump no_password ; exit if not found
pchk_password:
purlparm buf,PWD_CMD ; search for password parameter
pjumpne ok_password ; OK exit if not given
;;pprintv "PW= found: [buf]=",[buf]
;;pprint "<br>\r\n"
#ifdef PASSWORD_IN_SEEPROM
purl2scmp buf,password
pjumpne bad_password ; exit if not a match
#else
pmovwi PPWBUF,password ; setup to loop thru password
pmovwi PWCNT,0 ; zero loop counter
pchk_password_loop:
purl2s PWCH,[buf],1 ; move URL character to SRAM
pee2s PWCH2,[PPWBUF],1 ; move password byte into SRAM
;;pprintv "buf=",[buf]
;;pprintv "PWCNT=",[PWCNT]
;;pprintb "PWCH=",PWCH,1
;;pprintb "PWCH2=",PWCH2,1
;;pprintv "PPWBUF=",[PPWBUF]
;;pcrlf
pcmpbi PWCH2,[PWCH] ; check for match
pjumpne bad_password ; exit if not a match
pincw buf ; bump our pointers
pincw PPWBUF
pincw PWCNT
pcmpwi PWCNT,NUM_PASSWORD_CHARS ; are we done?
pjumpne pchk_password_loop ; loop back if not
#endif
ok_password:
pcmpwi buf,[buf] ; show match (Z flag=1)
pret
bad_password:
;;pprint "Oops! Bad password!<br>\r\n"
;;pcall pshow_password
;;pprint "<br>\r\n"
pcmpwi buf,0 ; force mismatch (Z flag=0)
pret
no_password:
;;pprint "Oops! No password!<br>\r\n"
pcmpwi buf,0 ; force mismatch (Z flag=0)
pret
pshow_password:
purlparm buf,PWD_CMD ; search for command string
pjumpne pshow_password_exit ; exit if not found
pprinturl buf,0 ; print passed string
pshow_password_exit:
pret
pshow_real_password:
#ifdef PASSWORD_IN_SEEPROM
pprint password
#else
pmovwi PPWBUF,password ; setup to loop thru password
pmovwi PWCNT,0 ; zero loop counter
pshow_real_password_loop:
pee2s PWCH,[PPWBUF],1 ; move password byte into SRAM
pputc [PWCH] ; print byte
pincw buf ; bump our pointers
pincw PPWBUF
pincw PWCNT
pcmpwi PWCNT,NUM_PASSWORD_CHARS ; are we done?
pjumpne pshow_real_password_loop
#endif
pret
pset_password:
purlparm buf,PWD_CMD ; search for password parameter
pjumpne no_password ; exit if not found
#ifdef PASSWORD_IN_SEEPROM
purl2s buf+2,[buf],NUM_PASSWORD_CHARS ; move password characters to SRAM
pjump pset_write_seeprom ; jump to pcode in flash
.text
; this pcode MUST BE located in flash (not SEEPROM)!!!
pset_write_seeprom:
ps2see password,buf+2,NUM_PASSWORD_CHARS ; move from SRAM to SEEPRROM
pret
#else
purl2s buf+2,[buf],NUM_PASSWORD_CHARS ; move password to SRAM
ps2ee password,buf+2,NUM_PASSWORD_CHARS ; move from SRAM to EEPROM
pret
#endif
.eseg
Back
|
|
|