Use Jolla Phone to share Wifi via USB

Recently I got a new Surface Pro 4, and starts to use it as my main laptop. I’m glad that it can work with Linux quite well. But it does have some issue that I can’t live with: wifi will stop working after hours randomly.

Though someone points a workaround to me on reddit, but it does not work for me. Fortunately, I was able to just use my usb ethernet at that time. But recently, I moved my seat at home to a place where I couldn’t reach the ethernet cable, so I has been forced to use wifi since then.

Luckily, I found a thread that indicated that I can make my Jolla phone to share the internet via USB. To make it short, one just need to execute

pkcon install usb-moded-connection-sharing-android-config

with developer account and restart the phone.

But later I found that it only works with Cellular network but not with wifi. I digged into the related usb-moded code to confirm that. The implementation explicitly disables wifi and enables cellular network for sharing.

But this is not the end of the story. I found I can still manually enable wifi after select Internet sharing as usb mode. But the network itself doesn’t work, because the implementation only adds the masquerade iptables rule for the cellular network. So I just tried to add my iptables rule manually via:

iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADE

And it works!

Then I created an expect(1) script to ssh to phone and execute the iptables command automatically, so now I can happily use Jolla to connect the wifi network for me, just like using a wifi dongle. I still need to configure the dns server manually via networkmanager for my local connection because the dns server pushed by dhcp server is for cellular network, but that’s good enough since I can even use google’s public dns server blindly if I don’t are too much about the dns speed.

This iptables rule also seems to be persistent if you don’t restart the phone, so I’m also considering to add it when the phone boots. For now I’m happy with my current solution.

Posted in Linux | Tagged , , , | Leave a comment

同一台电脑的 Linux/Windows 系统的蓝牙连接同一个设备

http://ubuntuforums.org/showthread.php?t=1479056

方法从这里找到的,不过在这里有少许区别。

情况是这样的,如果你有同一个蓝牙设备,想要同时在 Windows / Linux (或者多个 Linux 系统)使用,你会发现在一个系统下配对之后,在另一个系统连接时会连接失败。因为蓝牙在配对后会生成一个 key,而这个 key 在不同的系统下并没有共享。

那么问题就是怎么修改/读取这个 key 了。

Windows 下,key 保存在注册表中。我没有尝试,但是上面的链接提到即使管理员模式也无权访问?所以改为从 Linux 下读取注册表的方式访问Key 。从 Linux 下面也可以使用方便的工具 chntpw 读取。首先备份一个 Windows\System32\config\SYSTEM 文件,然后使用 chntpw 即可读取。我的 key 在 \ControlSet001\Services\BTHPORT\Parameters\Keys\[Bluetooth adapter MAC address]\[Bluetooth device MAC address] 下。

在执行 chntpw -e [SYSTEM 文件的路径] 之后,可以使用 cd / ls 像访问文件一样访问。在到了最终的目录之后,使用 hex [key 名称] 查看对应的 key 的 16 进制。

在 bluez 5 的环境下,配对后会在 /var/lib/bluetooth/[Bluetooth adapter MAC address]/[Bluetooth device MAC address]/info 这个文件内写入设备的信息,格式就是普通的 ini。找到 [LinkKey] 下面的 Key= 行,填入对应的 16 进制 Key (无空格)即可。

总结一下流程:

  1. 在 Linux 下先配对,生成对应的 info 文件。
  2. 然后在 Windows 下重新配对,产生新的 Key,并存在了注册表中。
  3. 再到 Linux 修改对应文件。
Posted in Linux | Tagged , | 1 Comment

On porting Fcitx KCM module to KF5

Porting Fcitx KCM to KF5 is not that easy. It’s not only about porting kcm itself, but also porting missing part of fcitx-qt5 to Qt5 (mostly widgets). The old pkgconfig file is quite messed up, so I decided to experiment with extra-cmake-modules (ECM) a bit.

I found that fcitx-qt5 could be nicely split into two sub-modules, so I tried to use similiar CMake trick like KF5. So we now have nicely split FcitxQt5DBusAddons and FcitxQt5WidgetsAddons in fcitx-qt5 repo.

ECM and new cmake provide a standardized way to create find_package cmake scripts and I really like it. Another thing that I want to mention is that target_include_directories(xx INTERFACE xx) is  great. If a library adopts this method, the long list inside include_directories is not required anymore, target_link_libraries will resolve all needed include_directories for you and everything will work like magic.

The keyboard layout previewer in kde4 kcm is not ported yet because there’s some X11 related library usage, which need to be ported to xcb because Qt5 is using xcb instead of libX11. But overall it’s usable, and I fixed a quite nasty old bug in KCM too.

I also played a bit with C++ 11 Lambda, and it made my porting job simpler. In old KDialog’s world, there’s a signal passes KDialog::ButtonCode. Though QDialogButtonBox also provides QDialogButtonBox::StandardButton, QDialogButtonBox’s “clicked” signal only passes QAbstractButton pointer. So I used following lambda function to preserve the old behavior.

[this, buttonBox](QAbstractButton* button) {
    this->buttonClicked(buttonBox->standardButton(button);
}

which is quite handy to use.

And here comes a mandatory screenshot, sorry for some Chinese character on it because LANG trick can’t affect all strings (some come from another process via DBus).

kcm-fcitx1

Posted in fcitx development | Tagged | 3 Comments

龙卷风和传奇

虽然是个老故事,也很短。

很久之前的某天我们在 IRC 的 #chakra-devel 上扯淡,突然有个人说,那边来了个龙卷风。

正当其他人为他担心的时候,他又说,没关系,这房子很结实因为是我造的。

众人皆拜服。

]]>

Posted in 日志 | Leave a comment

这个坑不是挖坑的坑,只是随便说说的一些可能比较坑的事情。

比如合租这个事情,找到一个糟糕的室友合租可以有多糟糕?

可以非常糟糕,以下是一些找到的情况。

首先,问题就在于你和你的室友是一起和房东签的合同,任何一方想要搬走都是break lease。

break lease 的罚款是建立在房租上的,到合同到期日为止,剩下的所有房租是可能产生的罚款的最大的量。

当然,为了保护租户,房东也不会和你较劲,一般来讲,如果你找到一个下家就可以转租出去。然后不会因为break lease而被罚款。

房东是不管你们内部如何分配房租的。他只care收到你们完整的金额,那么如果一开始你们就只有口头的协商,就会存在潜在的问题。

假设你的室友某天开始不打算交房租了,房东可能会把房租的责任都放到你身上,因为force你的室友交房租需要你们内部解决。否则你自己的信用也可能会受到影响。

当初房租可能是一个人承受不了的,所以你可能自己陷入一些财政危机当中。

而实质的建议也只有去找房东坦白寻求同情。所以你看到这事是有多么的不靠谱了。

想要从你室友那讨回你应该的部分也只能去和他打官司。找下家,找新房子,和房东得瑟,还有精神上的压力 ¬ _ ¬ ,没人能赔偿得了了。

即使不是房租问题,因为任何原因合租搬家也比较困难。如果你室友你觉得是混蛋,他又不想搬走,怎么回避下家问为什么要搬走的问题?怎么回避你室友对你找的人不满意的问题?

所以核心建议就是:

1、只和绝对信任的人合租。

2、只单独和房东租。

其次就是,划分责任范围也是很重要的。合租的话先在你们之间签个 agreement 是比较好的办法。

=-=-=-=-=
Powered by Blogilo

Posted in 日志 | 9 Comments