2022年2月20日日曜日

pCP Mobile:自宅WiFiとスマホテザリングのIPアドレスを固定したい(原因判明)

接続しているSSIDでIPアドレスを変更したい(wlan0.sh編part2)

なぜSSIDを正しく評価できないのだろう。。。?
そもそも、wlan0.shが動く際にWiFiに接続できているのか??
と思いスクリプトを変更し状態を確認してみる。

1.正しく評価できない原因は?
tc@pCP:/opt$ sudo vi wlan0.sh 
tc@pCP:/opt$ cat wlan0.sh 
#!/bin/sh
# Maintained by piCorePlayer
echo "[ INFO ] Running $0..."
NWOK=1
until [ -d /sys/class/net/wlan0 ]
do
    if [ $((CNT++)) -gt 50 ]; then
        echo -n "${RED}No Ethernet Adapter [wlan0] Found!${NORMAL}"
        NWOK=0
        break
    else
        echo -n "."
        sleep 0.5
    fi
done

echo iwconfig wlan0

if [ $NWOK -eq 1 ]; then
    ifconfig wlan0 192.168.3.90 netmask 255.255.255.0 broadcast 192.168.3.255 up
    route add default gw 192.168.3.1
    sudo echo nameserver 192.168.3.1 > /etc/resolv.conf
    /etc/init.d/settime.sh &
fi

変更後は保存してリブート!
tc@pCP:/opt$ sudo filetool.sh -b
Backing up files to /mnt/mmcblk0p2/tce/mydata.tgz / 
Done.
tc@pCP:/opt$ sudo reboot

起動ログを確認してみる。

tc@pCP:~$ cat /var/log/pcp_boot.log
Starting piCorePlayer v8.0.0 startup...
Starting rngd using /dev/hwrng... Done.
Checking for boot files on mmcblk0p1...
  Trying to mount /dev/mmcblk0p1.
  ssh file found on mmcblk0p1.
  newpcp.cfg not found on mmcblk0p1.
Setting default piCorePlayer repository...
Generating sound card drop-down list...
Starting WiFi on wlan0...
[ INFO ] Running /usr/local/etc/init.d/wifi...
wlan0     IEEE 802.11  ESSID:off/any  
          Mode:Managed  Access Point: Not-Associated   Tx-Power=20 dBm   
          Retry short  long limit:2   RTS thr:off   Fragment thr:off
          Encryption key:off
          Power Management:off
Starting WiFi... Done.
Loading piCorePlayer configuration file... Done.
Loading pcp-lms-functions... Done.
Waiting for sound card Headphones to populate......................................... Failed to find Headphones... Done (42).
Waiting for network. Done (1).
Starting Openssh server... Done.
Starting Squeezelite and/or Shairport-sync... Done.
Starting httpd web server... Done.
Starting to advertise pcp.local... Done.
Setting CPU scaling governor to ondemand... Done.
Creating static footer... Done.

Finished piCorePlayer v8.0.0 startup.

なんと、「TP-Link」が無い!!
「off/any」になってる。
この時点では自宅WiFiには接続されてないんだ。。。(T_T)

2.supplicant(認証用クライアント)の状態は?
WiFi接続する際のsupplicantで使用するコマンドはwpa_cliのようだ。
試してみる。

tc@pCP:/opt$ wpa_cli
wpa_cli v2.9
Copyright (c) 2004-2019, Jouni Malinen <j@w1.fi> and contributors

This software may be distributed under the terms of the BSD license.
See README for more details.


Selected interface 'wlan0'

Interactive mode

> stuatus
bssid=40:xx:xx:xx:xx:32
freq=2452
ssid=TP-Link_BC32
id=0
id_str=Home
mode=station
wifi_generation=4
pairwise_cipher=CCMP
group_cipher=TKIP
key_mgmt=WPA2-PSK
wpa_state=COMPLETED
ip_address=192.168.3.90
address=88:xx:xx:xx:xx:5e
uuid=e92axxxx-xxxx-xxxx-xxxx-xxxxff278537
> q
tc@pCP:/opt$

という具合にオプションなしで起動するとインタラクティブモードになるようだ。
オプションを指定して実行するとコマンドとして処理できる。

tc@pCP:/opt$ wpa_cli -iwlan0 status
bssid=40:xx:xx:xx:xx:32
freq=2452
ssid=TP-Link_BC32
id=0
id_str=Home
mode=station
wifi_generation=4
pairwise_cipher=CCMP
group_cipher=TKIP
key_mgmt=WPA2-PSK
wpa_state=COMPLETED
ip_address=192.168.3.90
address=88:xx:xx:xx:xx:5e
uuid=e92axxxx-xxxx-xxxx-xxxx-xxxxff278537

こんな感じで状態が確認できることが分かった。
早速wlan0.shに追記して調べてみる。

tc@pCP:/opt$ sudo vi wlan0.sh 
tc@pCP:/opt$ cat wlan0.sh 
#!/bin/sh
# Maintained by piCorePlayer
echo "[ INFO ] Running $0..."
NWOK=1
until [ -d /sys/class/net/wlan0 ]
do
    if [ $((CNT++)) -gt 50 ]; then
        echo -n "${RED}No Ethernet Adapter [wlan0] Found!${NORMAL}"
        NWOK=0
        break
    else
        echo -n "."
        sleep 0.5
    fi
done

wpa_cli -iwlan0 status
iwconfig wlan0

if [ $NWOK -eq 1 ]; then
    ifconfig wlan0 192.168.3.90 netmask 255.255.255.0 broadcast 192.168.3.255 up
    route add default gw 192.168.3.1
    sudo echo nameserver 192.168.3.1 > /etc/resolv.conf
    /etc/init.d/settime.sh &
fi

変更後は保存してリブート!
tc@pCP:/opt$ sudo filetool.sh -b
Backing up files to /mnt/mmcblk0p2/tce/mydata.tgz / 
Done.
tc@pCP:/opt$ sudo reboot

起動ログを確認してみる。

tc@pCP:~$ cat /var/log/pcp_boot.log 
Starting piCorePlayer v8.0.0 startup...
Starting rngd using /dev/hwrng... Done.
Checking for boot files on mmcblk0p1...
  Trying to mount /dev/mmcblk0p1.
  ssh file found on mmcblk0p1.
  newpcp.cfg not found on mmcblk0p1.
Setting default piCorePlayer repository...
Generating sound card drop-down list...
Starting WiFi on wlan0...
[ INFO ] Running /usr/local/etc/init.d/wifi...
wpa_state=SCANNING
address=88:xx:xx:xx:xx:5e
uuid=e92axxxx-xxxx-xxxx-xxxx-xxxxff278537
wlan0     IEEE 802.11  ESSID:off/any  
          Mode:Managed  Access Point: Not-Associated   Tx-Power=20 dBm   
          Retry short  long limit:2   RTS thr:off   Fragment thr:off
          Encryption key:off
          Power Management:off
          
Starting WiFi... Done.
Loading piCorePlayer configuration file... Done.
Loading pcp-lms-functions... Done.
Waiting for sound card Headphones to populate......................................... Failed to find Headphones... Done (42).
Waiting for network. Done (1).
Starting Openssh server... Done.
Starting Squeezelite and/or Shairport-sync... Done.
Starting httpd web server... Done.
Starting to advertise pcp.local... Done.
Setting CPU scaling governor to ondemand... Done.
Creating static footer... Done.

Finished piCorePlayer v8.0.0 startup.

なんと、「SCANNING」スキャン中だってさ。。。
原因は判明したが、さてどうするか、う~~ん。。。

0 件のコメント:

コメントを投稿