# wrong time?

Tue May 6 15:53:15 EDT 2008

```My solution

#!/bin/sh
#/etc/timecheck.sh
#
twodigit()
{
if [ \$1 -lt 10 ];then
echo 0\$1
else
echo \$1
fi
}

#MM=two digit month
#DD=two digit day
#HH=two digit hour in 24 hour
#mm=two digit minute
#YYYY=four digit year
seconds_since_epoch_to_MMDDHHmmYYYY()
{
year=0000
month=0
day=0
hour=0
minute=0

epochyear=1970

#just a close proximity I can be a bit off
#(a number of days) since most certs are
#good for a year period.

let secondsinminute=61
let secondsinhour=60*\$secondsinminute
let secondsinday=24*\$secondsinhour
let secondsinmonth=30*\$secondsinday
let secondsinyear=12*\$secondsinmonth

let years=\$1/\$secondsinyear
let year=\$epochyear+\$years

let subtractyears=\$years*\$secondsinyear
let monthsleft=\$1-\$subtractyears
let months=\$monthsleft/\$secondsinmonth
let month=\$months+1

let subtractmonths=\$months*\$secondsinmonth
let daysleft=\$monthsleft-\$subtractmonths
let days=\$daysleft/\$secondsinday
let day=\$days+1

#Since again I don't need to be exact the
#only month that has less than 30 days needs
#checked

if [ \$month -eq 2 ];then
if [ \$day -gt 28 ];then
day=28
fi
fi

let subtractdays=\$days*\$secondsinday
let hoursleft=\$daysleft-\$subtractdays
let hours=\$hoursleft/\$secondsinhour
let hour=\$hours

let subtracthours=\$hours*\$secondsinhour
let minutesleft=\$hoursleft-\$subtracthours
let minutes=\$minutesleft/\$secondsinminute
let minute=\$minutes

let subtractminutes=\$minutes*\$secondsinminute
let secondsleft=\$minutesleft-\$subtractminutes
if [ \$secondsleft -gt 59 ];then
second=59
else
second=\$secondsleft
fi
echo -n `twodigit \$month``twodigit \$day`
echo `twodigit \$hour``twodigit \$minute`\$year
}

TMPFILE=/var/volatile/wpastuff

wpa_supplicant -Dmarvell -iwlan0 \
-c/etc/wpa_supplicant.conf \
-w 1>\$TMPFILE 2>/dev/null &
#wait for wpa_supplicant to try and connect
sleep 5
killall wpa_supplicant
while [ "`ps|grep wpa_supplicant \
|grep -v grep`" != "" ];do
sleep 1
done

vars=`cat \$TMPFILE |grep now \
|cut -d "(" -f2|cut -d ")" -f1`
if [ "\$vars" != "" ];then
for var in \$vars ;do
let \$var
done
let diff=\$not_after-\$not_before
let halfdiff=\$diff/2
let now=\$not_before+\$halfdiff
date `seconds_since_epoch_to_MMDDHHmmYYYY \$now`
fi

On Mon, May 5, 2008 at 4:07 PM, Jeff Sadowski <jeff.sadowski at gmail.com> wrote:
> I have a mobile linux device that has no RTC as such if I start the
>  device to connect without setting the clock first I get
>
>  wpa_supplicant -Dmarvell -iwlan0 -c/etc/wpa_supplicant.conf -w
>  ioctl[SIOCSIWPMKSA]: Invalid argument
>  Trying to associate with 00:0b:0e:26:d2:80 (SSID='ABBA1X' freq=2437 MHz)
>  Associated with 00:0b:0e:26:d2:80
>  CTRL-EVENT-EAP-STARTED EAP authentication started
>  CTRL-EVENT-EAP-METHOD EAP vendor 0 method 25 (PEAP) selected
>  X509: Certificate not valid (now=1210001377 not_before=1156333193
>  not_after=1187869193)
>  CTRL-EVENT-TERMINATING - signal 2 received
>
>  I would like to have the device set the time automatically but only if
>  it has to.
>  Is there a way to have it try and connect first without really connecting?
>  Just have it spit the above information to a script so that it can
>  determin it needs to set the time to half way between
>  not_before=1156333193 and not_after=1187869193
>
>  Or better yet is there a way to have wpa_supplicant set the time as it
>  is connecting?
>
```