顯示具有 Study Notes 標籤的文章。 顯示所有文章
顯示具有 Study Notes 標籤的文章。 顯示所有文章

2010年11月15日 星期一

Wi-fi 干擾與 AP Channel 設定

最近為了一些原因看了一些有關 WiFi 的文章,赫然發現原來 WiFi 這麼容易遇到干擾啊。也順便了解了之前設定 Wireless AP 時,一直不知道那是幹啥用的 channel 是啥。

原來 Wifi 把 2.4GHz (~2.483GHz) 的頻段切割成 11 (依照國家不同,有些切到 15)個頻段,每一個頻段就是一個 channel。因為相同頻率的信號波會互相干擾,所以當同一個地點有兩個無線訊號使用相同 channel 時,802.11 設計了一套避免干擾的方法,那就是:等別人用完了再用!

簡單的說,就是發射訊號前先檢查 channel 裡有沒有訊號正在傳送,有的話,就「等」。等到 channel 安靜下來,它才開始傳送自己的資料。顯而易見的,這個方法會影響到傳輸的速率。所以當同一個地點有很多 wifi 使用相同 channel 的話,看起來訊號很強,其實連線的問題很大!

所以,要避免這種干擾。最好讓環境裡的無線訊好號越少越好(我知道,這可能不是自己能控制的事);再不然,至少不要讓這些無線網路使用相同的(或鄰近的)channel 來減少訊號干擾的機會。

以切成 11 個 channel 來說,有三個 channel 是幾乎不會互相覆蓋到的:1、6、11。所以理論上把自己的 AP 設成這三個 channel 應該是最好的。

而根據像我這種不懂,把 AP 買回家用預設值換個密碼、設個 WEP 就上線的人應該不少。所以,我想把 channel 改到 6 或 11 應該可以避免不少干擾才是。

今天回家就試試看吧~

參考:IEEE 802.11 (wiki)
參考:避免2.4GHz ISM頻段各種類型無線設備干擾的技術

2010年11月2日 星期二

E220 HSDPA Study

There are three devices will appear in system when E220 USB device plug-in (with driver installed).

  1. Mass storage device (include driver, application and manual)
  2. 3G modem device (COM)
  3. Mobile Connect PC UI Interface device (COM)

There is a application called “Mobile Connect” will be installed with 3G modem driver. Which will use the 3th device in above list to communicate with 3G chip. (cause the 3G modem device has been locked by windows connection manager when connected, the application need another interface to get statistic from 3G chip)

MSMQ Auto Installation

There are several ways to install (enable) MSMQ automatically.

The major issues are:

  1. The way to install MSMQ in different OS version are different.
  2. The supported components of MSMQ are different in different OS.

In below detail procedure for install MSMQ, you will see I enable different MSMQ components for different OS version. Those components are tested for me to use. If you need more components, you need to add them in command line, or un-attend file to enable them.

2010年10月31日 星期日

Research on locked resources

I am keep looking at how to stop service, drivers and applications to release resources (file, database) to make backup & restore process more smoothly.

This post is a note of the testing result, it will keep updating when anything was found.

2010年10月29日 星期五

2010年10月26日 星期二

Mobile (CE) hive-base registry diagram

Again, I made a diagram for hive-base registry.

擷取

Key points of this diagram:

  1. Three kinds of HIVE in mobile system
  2. Filesys,dll will mount Boot.hv from ROM first
  3. Boot.hv used to pre-load root partition (storage driver, marked as bootable) and locate system hive position (HKLM\Init\SystemHive)
  4. Default.hv is the ROM portion of system hive
  5. System.hv stores the changes of default.hv
  6. Again, current users user.hv will be located by system hive
  7. User.hv in root file system stores the changes of user.hv in ROM image
  8. Whatever system hive or user hive, system will store ROM portion’s MD5 checksum as signature
  9. When filesys.dll load system hive and user hive from root file system, the signature will be checked. If signature not match, the system.hv and user.hv in file system will be delete
  10. The signature mechanism cannot be disabled
  11. There are OEM I/O controls can force system to delete system.hv and user.hv in root file system

突然想到,解釋這麼落落長,那不就代表這張圖沒有用…目瞪口呆

Mobile (CE) File System Diagram

I made a diagram for my study report.

擷取

Key points of this diagram:

  1. When clean boot, filesys.dll will use initobj.dat (in ROM image) to create root file system.
  2. ROM image content ‘flat’ file system, no directory, only files
  3. ROM image will be mounted at “\windows” folder
  4. Folder “\windows” actually contents files in ROM and files in root file system, object store will handle the integration.
  5. External storage like SD card will be mounted at “\Storage Card” folder; Driver can define the mount point name as they want.
  6. If multi external storage exists, device management add sequence ID on the end of mount point name, like “\Storage Card 2”

2010年10月25日 星期一

Schema of CEDB

Except the strange terminology on Windows CE database, I finally got another key point that why I am struggle on study CEDB document. That is:

There is no schema on CEDB database.

What a key point of CEDB feature, but I did not notice that! Cause I already used to other database engines on the world. Without this realization, it’s hard to understand the CEDB APIs.

Each record in CEDB refers to a set of data. Each data has a unique property ID and data type. CEDB allow records in same database has different properties (but I really don’t know who need this).

With this cognition, everything is clear. Why CeCreateDatabaseEx() API does not have parameter for properties, why CEDB using CeWriteRecordPropertiresEX() API to create properties, …, etc.

I think, I really waste a lot of time on study CEDB with wrong assumption… 傷心

2010年10月24日 星期日

Something about EDB and CEDB

Although MSDN mentions that EDB is designed to replace CEDB, but I did not find documents descript about how to detect the database in my device is EDB or CEDB. And more important is, I do not how to use EDB APIs in my develop machine (When using VS2008 with SDK 6.0, it using CEDB APIs by default, and I don’t know how to switch it).

Finally, I got some post that really help me to solve my problem.

2010年10月15日 星期五

Enumerate database in volume

As I said in [Windows Mobile (CE) Database Study], the terminology of CEDB and EDB is almost killing me. The topic is enumerate  tables in database, if using all other common database engines.

I cannot find any document descripts CEDB and EDB which one used in Windows Mobile 6.1 (my test device). But I cannot use EDB only APIs on my develop environment (VS2008 + WM 6.1 SDK) , so the sample code here is using CEDB.

Here is the code piece, follow the sample code in [Enumerate DB Volumes], we got the DB volume’s CEGUID (in variable ‘guid’) and then try to enumerate all database (tables) in that volume.

HANDLE hFind = CeFindFirstDatabaseEX(&guid, 0);
CEOID oid = 0;
while ((oid = CeFindNextDatabaseEx(hFind, NULL)) != 0) 
{
        CEOIDINFOEX oidinfo;
        memset(&oidinfo, 0, sizeof(CEOIDINFOEX));
        oidinfo.wVersion = CEOIDINFO_VERSION;

        if ((CeOidGetInfoEx2(&guid, oid, &oidinfo))
        {
                /// TODO: print out oidinfo.infDatabase.szDbaseName
        }
}
CloseHandle(hFind);

Back to enumeration, you can use CREATE_INVALIDGUID to initialize variable 'guid’, then the code will enumerate all database (tables) in all mounted volume (I am not sure the order)..

And you can specified a PCEGUID in the second parameter of CeFindNextDatabaseEx() function to get the volume’s GUID which the database belongs to.

Below is the enumeration of my device, just for reference.

VOL: \Documents and Settings\default.vol
        ScheduleU
        ScheduleS
        ScheduleGroupU
        ScheduleGroupS
VOL: \ReplStorVol
        ReplStor
VOL: \mxip_notify.vol
        DB_notify_queue
        DB_notify_events
VOL: \mxip_swmgmt.vol
        SwMgmtMetadataStore
VOL: \cemail.vol
        fldr3100001d
        pmailVolumes
        pmailNamedProps
        pmailMsgClasses
        pmailOldTables
        pmailMsgs
        pmailFolders
VOL: \mxip_system.vol
        \ConfigMetabase
VOL: \mxip_lang.vol
        \MetabaseOptions
        \MetabaseLabels

2010年10月14日 星期四

Hive-base registry initialization

Original document:
http://msdn.microsoft.com/en-us/library/ee489764.aspx

Sequence

I only list items I may needed

1. Mount boot hive (Boot.hv) from ROM
2. Loads and initializes Storage Manager (HKLM\System\StorageManager)
3. Boot phase zero
4. Initialize system locale
5. Boot phase one
6. Device.exe (if needed ??)
7. Wait for file system contains system hive ready (MountAsBoot?)
8. Mounts ROM portion of system registry (\Windows\Default.hv)
9. Check IOCTL_HAL_GET_HIVE_CLEAN_FLAG for clean system hive
10. Check HIVECLEANFLAGS_SYSTEM for clean system hive
11. Load system.hv from file system
12. Check system hive signature for clean system hive
13. Swap out boot registry hive
14. Check IOCTL_HAL_GET_HIVE_CLEAN_FLAG for delete user.hv
15. Check HIVECLEANFLAGS_USERS for delete user.hv
16. Mounts ROM portion of user hive (\Windows\User.hv)
17. Load user.hv from file system
18. Check user hive signature for clean user hive

Boot phase

Phase 0: system locale not ready
Phase 1: system locale ready, but total registry no loaded
Phase 2: system locale ready and total registry has been loaded

Enumerate EDB volumes

I wrote a test application to enumerates all EDB volumes on my WM6.1 devices. Here is the code piece:

CEGUID guid;
DWORD  dwErr;
WCHAR  wszMsg[255];
WCHAR  wszName[255];

CREATE_INVALIDGUID(&guid);

while (CeEnumDBVolumes(&guid, wszName, 255))
{
        StringCchPrintfW(
                wszMsg, 255, L"VOL: %s\n", wszName);
        OutputDebugStringW(wszMsg);
}

if (GetLastError != ERROR_NO_MORE_ITEMS)
{
        OutputDebugString(L”Unexpected stop\n”);       
}   

According the MSDN, the size of wszName should be enough to CEDB_MAXDBASENAMELEN. But actually I got ERROR_INSUFFICIENT_BUFFER error when using that size.

After increase the size to 255, the enumeration finish normally, and here is the output in my device.

VOL: \Documents and Settings\default.vol
VOL: \ReplStorVol
VOL: \mxip_notify.vol
VOL: \mxip_swmgmt.vol
VOL: \cemail.vol
VOL: \mxip_system.vol
VOL: \mxip_lang.vol

It’s more than I expected….嚎啕大哭

And notice the first one, the length is absolutely larger then CEDB_MAXDBASENAMELEN (32), that means the reference guide of CeEnumDBVolumes() was wrong.

Back to the list I got, there are more than that when I searching the *.vol files on root file system. Cause CeEnumDBVolumes() only list the mounted database volumes.

And of course, the volumes listed has been locked after my mobile device boot up, there is a long road for me to understand how to release them for backup/restore purpose.

2010年10月13日 星期三

Windows Mobile (CE) Database Study

Notes about study CEDB and EDB on Windows Mobile (CE).

Terminology

When study MSDN about CEDB and EDB, some wording keep confusing me. Cause CEDE and EDB using different terminology with other common database engine.

EDB and CEDB term SQL Server Compact term
Sort order Index
Data type Data type
Property Column
Record Row
Database Table
Volume Database

Especially the Database mapping to Table one keep confusing me on reading the document…

Database Volume

We can see CEDB and EDB as a file-base database like Sqlite. A volume is a file including multi database (table, you see why I am confusing).

Before using the database, you need to mount (‘open’ in normal terminology) the volume. If the volume is not exists, you need to create (create a new file using CEDB API) first. When you don’t need the database anymore, you need to un-mount (‘close’) the volume.

There is a default database volume in CE (Mobile) system used by object store. It will be mounted when system start up and released when system shutdown (that means the file will be locked in whole running cycle).

And applications can create volume in any location they wanted, including external storage (like SD card).

The EDB and CEDB APIs using CEGUID as identity to access a volume, database or even a record. For the detail usage, need to refer to each method’s document for detail.

Database Backup / Restore

Obviously, we need different procedures to handle the default volume (object store) and others.

For extra created database volume, we just need to stop all process which using these database volume. And then we can just follow the root file system backup & restore procedure. It should be a easy one.

For object store database volume….

If I can find the way to un-mount the object store, it should be easier to handle it like other database volume. But seems it’s not so easy to find the way.

Otherwise, we can enumerate all object store database and dump them into our format. And then push them back when restore. I am not sure if there is some database has write-protect, but I think it should be not….

2010年10月11日 星期一

Windows Mobile (CE) File System Study

The same reason as the previous one for Windows mobile registry. This post is the notes of Windows mobile file system study.

FILE ATTRIBUTE

Theoretically, we can scan all files and folders in root system, and then using GetFileAttributes to get the attribute. And of course we can use the attribute to differentiate the file is stored in ROM image, writable root file system or external media storage (like SD card).

FILE_ATTRIBUTE_INROM Indicate the file store in ROM image. It’s read-only and cannot be modified. And we don’t need to worry about it on backup function.
FILE_ATTRIBUTE_SYSTEM The file is used by the OS.
FILE_ATTRIBUTE_HIDDEN The file or directory is hidden. I am not sure if we can find hidden file using  FindFirstFile API.
FILE_ATTRIBUTE_ARCHIVE MSDN says application use this attribute to mark files for backup or removal. I am not really understand what he means. I need more study on this, maybe that relative with backup and restore function we wanted.
FILE_ATTRIBUTE_TEMPORARY Temp files, we can ignore them for backup function.

There are more attributes list in MSDN, I don’t know if I miss anything important for backup application. I need more testing on real device for detail.

SCAN STORAGE

I had write a testing code to scan all storages on my mobile device follow the sample here.

And I get output like this:

Store: SMFLASH
    Part: Name(Part00) Vol() FS(BOOT) ATT(0)
    Part: Name(Part01) Vol() FS(RAWFS) ATT(0)
    Part: Name(Part02) Vol() FS(imgfs.dll) ATT(16)
    Part: Name(Part03) Vol() FS(fatfsd.dll) ATT(16)
Store: DSK1:
    Part: Name(Part00) Vol(\Storage Card) FS(fatfsd.dll) ATT(16)

I can see I have one SD card using FAT file system and mounted on “\Storage Card”. And the internal storage is SMFLASH with 4 partitions.

I can understand that we don’t need to care about partition 0 and 1, but I still cannot know which is the root file system we are using. (The partition attribute 16 means READONLY, AUTOFORMAT and MOUNTED.)

Ps. The sample code using library storeapi.lib, this library does not exists in Windows Mobile SDK. I got it from WM616 adapter kit.

FILE SYSTEM BACKUP PLAN

Theoretically, if we can list all files which are not store in ROM image, then we can create the file backup image for later restore.

I had wrote a test application which scan all files in root file system to find out the files and directories does not store in ROM image using API FindFirstFile and FindNextFile.

But we still have issues need to be solve:

1. When mobile OS running, lot of files were been locked for read (for example: driver dll in windows folder). I cannot copy those files for creating backup image.

2. Like previous issue, of course the running (locked) files cannot be write for restoring.

API initializes sequence by filesys.dll

According to MSDN, here are the APIs initialized by filesys.dll in sequence:

  1. Database APIs
  2. File system APIs
  3. Point-to-Point message queue APIs
  4. Event log APIs
  5. Registry APIs

I had not read the detail yet, but I am surprising the database API initialed before file system. The database does not need to refer to file system??

Windows Mobile (CE) Registry Study

I got a job from my leader about backup and restore system state of our company's handheld products which are using Windows Mobile 6.1. So, I start to study the Windows Mobile system architecture for the knowledge to backup the system.

This post is a study notes about the registry system in Windows Mobile.

Registry Type: RAM-base and HIVE-base

There are two types registry provides by Window CE: RAM-base and HIVE base.

RAM-base Registry means the registry keeps in Object-Stored. Of course when system shutting down, the data in RAM will lost. So OEM need to implement the architecture to save and restore the registry to/from storage when system shutdown and start up.

HIVE-base Registry means the registries are saved in file system in HIVE file (like other Windows systems). There are three HIVE files in mobile system: boot hive, system hive and user hive.

Important: Windows Mobile 6.X only support HIVE-base registry.

Boot Hive, System Hive and User Hive

Boot hive stored in ROM and will be loaded when system startup (by filesys.dll). It contents the registry roots: HKEY_CLASS_ROOT, HKEY_LOCAL_MACHINE and HKEY_USERS. Once the boot.hv has been loaded, the filesys.dll will locate and load the system hive from registry [HKLM]\init\SystemHive. Once the system hive has been loaded, the boot.hv is discarded (OEM can define the system hive location and file name in his OS design).

System hive provides the same registry roots as boot hive. Any modification about those registry roots will stored in system hive (boot hive in ROM will not change unless perform ROM upgrade).

User hive contents the registry for logon user (HKEY_CURRENT_USER). The location of the user hive can be specified in [HKLM]\init\ProfileDir, and the file name is "user.hv".

Signature link Hive in ROM and Hive in File System

When system created the hive on file system on clean boot, it keeps a signature (MD5 of hive in ROM) in the hive. When filesys.dll loads the hive file in file system, it will check if the signature is match. If not, filesys.dll will force to clean the hive in file system and create a new one for it.

Cause the hive in file system normally presents the changes of the hive in ROM, this mechanism used to ensure the hive is valid for current ROM image.

This mechanism fixed in filesys,dll and cannot be disabled.

Backup and restore system hive

To backup the system hive, you can use "RegSaveKey" API. Although the API parameter supports to input registry ROOT key for saving, but actually it save whole system hive when you input the HKLM, HKCR or their sub keys.

To restore the system hive, you can use "RegReplaceKey" API. Providing the file you got from "RegSaveKey" to this API, and the system will un-mount the system hive and replace it by your file. And then you need to reboot the system to re-mount the new system hive.

The procedure here is used only for HIVE-base registry, for RAM-base registry, you need to refer MSDN by youself.

Backup and restore user hive

Like backup system hive, you can use "RegSaveKey" API with HKCU or his sub-key to save whole user hive.

To restore the user hive, you need to logoff the current user by using "SetCurrentUser(NULL)" API, the logoff will close and release the user hive file. And then you can use "CopyFile" API to replace the "user.hv" as yours.

And then we can use "SetCurrentUser" again to login the user (re-mount user hive), or need to reboot the system? I don't know….

HIVE format

The book "Windows Internals" has chapter to descript the HIVE detail, I have not read it yet.

According the MSDN and the book, there are two types HIVE format has been used: Standard format (1.3) or lastest format (1.5), I don't know what's the format be used in Window Mobile "RegSaveKey" API. Need more study.