New8210 Application Development Manual
New8210 Application Development Manual
APPLICATION DEVELOPMENT
MANUAL
V 0.1.2
Approved: Date:
2. General Introduction
If you want to develop in Linux system, you should install Linux system in your host
PC by yourself, we don’t offer any Linux OS install programs. We recommend using
RedHat Enterprise Server 6 x86 32bit version to development, and you should download
Linux SDK of NEW8210.
If you want to develop in Windows system, you should download Windows SDK of
NEW8210.
3. Function Introduction
4. Development Platform
If you want develop the application on Linux platform, you need to install a 32-bit
Linux system based on x86 platform (our SDK have not been certificated on 64-bit
Linux). You can also develop application on a virtual Linux by running virtual machine on
Windows system, at that time, you can develop application on Windows platform. Due to
we don’t offer SDK on Windows platform, so you can’t develop application on Windows
system directly.
The toolchain for NEW8210 is based on ARM cross compile toolchain which has the
version of glibc-2.9 gcc-4.3.4, the toolchain supports compile C,C++,Java,Object
C,Object-C++.It is easy to install, unzip cross compile toolchain which we provide is
enough:
The command above “-C /opt/compiler/” is unzip to /opt folder, you also can unzip
toolchain to anywhere you want, but please ensure that active user have the read and
write rights to the unzip folder.
After unzip to folder, use the command below to test whether the tool chains is
usable:
/opt/compiler/glibc-oabi-toolchain-arm-generic/bin/arm-unknown-linux-gnu-gcc -v
Target: arm-unknown-linux-gnu
Because this toolchain uses a high grade version of GCC toolchain, it needs
dynamic library mpfr-2.4.2, if your Linux system haven’t the dynamic library, or haven’t
the enough high grade version of dynamic library, it will report error libmpfr.so when using
this toolchain. Please download mpfr-2.4.2.tar.bz2, compile and install it again, step
below:
Unzip file:
cd mpfr-2.4.2
./configure –prefix=/usr
make
su
make install
exit
4.2. Install Eclipse for Linux
1. Download Eclipse
The server is: http://www.eclipse.org/downloads/ , please download Linux file
package have the version of Eclipse IDE for C/C++ Developers.
2. Unzip Eclipse
tar zxf eclipse-cpp-helios-linux-gtk.tar.gz -C /opt
Command above “-C /opt” is unzip to /opt folder, ensure that active user has read
and write rights. Also you can unzip to any other folders.
3. Run Eclipse
Execute “/opt/eclipse/eclipse” to run Eclipse, also you can create an application
launcher to run it.
The Windows compile toolchain for NEW8210 is based on ARM cross compile toolchain
which has the version of glibc-2.9 gcc-4.3.4, the toolchain supports compile C,C+
+,Java,Object-C,Object-C++.It is easy to install, unzip cross compile toolchain(glibc-oabi-
toolchain-arm-generic.zip) which we provide to C:\, and set the environment variable
PATH.
The box for adding a new user variable is shown below. Generally, this is likely to be a
directory that you use frequently but can be any string of less than 8192 bytes. The
maximum total size for all environment variables, including variable names and the
"equals" sign, is 32767 characters.
The next figure shows a box for editing a variable; in this case it is the PATH variable. Be
sure to remember to separate directory names with a semicolon.
Target: arm-unknown-linux-gnu
sysroot=/cygdrive/C/glibc-oabi-toolchain-arm-generic/arm-unknown-linux-gnu//sys-root --enable-languages=c,c++,objc,obj-c+
--with-mpfr=/home/Administrator/crosstool/bin/build/arm-unknown-linux-gnu/build/static
--enable-threads=posix
--enable-target-optspace --with-local-prefix=/cygdrive/C/glibc-oabi-toolchain-arm-generic/arm-unknown-linux-gnu//sys-root
1. Download Eclipse
The server is: http://www.eclipse.org/downloads/ , please download Windows file
package have the version of Eclipse IDE for C/C++ Developers.
2. Unzip Eclipse
3. Run Eclipse
4.5. Create application project
Choose menu File->New->C Project, or choose toolbar New->C Project, or right click
on Project Explorer windows’s blank, choose New->C Project:
4.5.2. configure application project
Configure application project name at Project Name, choose Hello World ANSI C
Project at Project type, if you chooses Empty Project , it will not generate default
program. We recommend automatic generate program which is contain main
function by Eclipse.Then click Next to go into next configuration.
Click Next again to go into next configuration:
In default condition, project create by Eclipse use gcc to compile the programs, and
the target is a application run on x86 platform; But our target system is ARM, of course it
can not run on x86 platform, so you need to configure the compile toolchain, cross
compile program which is running on ARM platform.
In Project Explore windows, right click the configured project, choose Properties
Firstly choose Configuration: [All configurations], so the configure below will be
available to both Debug version and Release version.
Choose “GCC C Compiler from Tool Settings” tag, modify “Command” on right side to
cross compile toolchain which we provide:
If you use Linux system, it should be:
/opt/compiler/glibc-oabi-toolchain-arm-generic/bin/arm-unknown-linux-gnu-gcc
If you use Windows system, it should be:
/cygdrive/c/glibc-oabi-toolchain-arm-generic/bin/arm-unknown-linux-gnu-gcc
Assume the Linux toolchain was installed in: /opt/compiler/glibc-oabi-toolchain-arm-
generic
Assume the Windows toolchain was installed in: C:\glibc-oabi-toolchain-arm-generic
Choose “GCC C Linker of Tool Settings” tags, modify “Command” on right side to cross
compile toolchain we provided:
If you use Linux system, it should be:
/opt/compiler/glibc-oabi-toolchain-arm-generic/bin/arm-unknown-linux-gnu-gcc
If you use Windows system, it should be:
/cygdrive/c/glibc-oabi-toolchain-arm-generic/bin/arm-unknown-linux-gnu-gcc
General Option: Here is a general linking option. Choose No shared libraries(-
static) if you need static link program;choose nothing if you need
dynamic link program. Usually, we choose dynamic link program.
Libraries Option: Here is used to configure linking assigned dynamic library and
configure path of search dynamic library, just like option –lxxxxx –
Lxxxxx.For example, if you want to link library directfb.so, just
need to add directfb in Libraries(-l), and add path of dynamic
library in Library search path(-L).
Miscellaneous Option: For NEW8210, we modify Linker flags to:
-marm -mapcs -mno-sched-prolog -mabi=apcs-gnu -mlittle-
endian -mno-thumb-interwork -msoft-float -Wl,-Map,"${PWD}/$
{ProjName}.map"
Shared Library Settings: Options here is available when compiling dynamic library, keep
default option when compiling application program.
Choose GCC Assembler of Tool Settings tag, modidy cross compile toolchain we
provide in right side’s Command to :
Here is used to configure compile options which is used when compiling assembly
file, usually application doesn’t use assembly language, so it is not need to configure.
In default condition, project create by Eclipse use gcc to compile the programs, and
the target is a application run on x86 platform; But our target system is ARM, of course it
can not run on x86 platform, so you need to configure the compile toolchain, cross
compile program which is running on ARM platform.
We setting the global environment configure in here, to avoid setting every project. Click the
menu “Window”-->select “Preferences” as follow figure:
Click the button “Add...” to add an environment variable “GCCPATH” as follow figure:
Select the “GCC C Compiler” in the tag “Tool Settings”, and change the Command as
follow:
$(GCCPATH)gcc
Preprocessor Option: Do not need to modify, keep default.
Symbols Option: Here is used to define/undefined some user-defined Macro while
compiling, just like add –Daaaaa -Ubbbbbb while compiling.
Include Option: Here is used to configure head file and its search path while be
compiled, just like add compile parameter –ixxxx.h -Lyyyyy.
Optimization Option: Here is used to configure compile optimized options, in default
condition, choose None(-O0) when compiling Debug version,
choose Optimize most(-O3) when compiling Release version.You
also can configure other optimized level by yourself: -O0 means
don’t optimize;-O1 means lightweight optimization;-O2 means
moderate optimization;-O3 means highly optimized, -Os means
optimize for space.
Debugging Option: Here is used to set the degree of compiled object code including
debug information .In default condition, choose Maximum(-g3)
when compiling Debug version; choose None when compiling
Release version;-g3 contains a lot of debug information, None
don’t contain any debug information.If you needs to debug, had
better choose –g or –g3; in releasing version, choose None.
Warnings Option: Here is used to configure compile warning option, default option is
All warnings(-Wall).
Miscellaneous Option: Here is used to define compile options for ourselves. For
NEW8210, we recommend set “Other flags” as:
-Wundef -Wstrict-prototypes -Werror-implicit-function-
declaration -Wdeclaration-after-statement -fsigned-char -marm
-mapcs -mno-sched-prolog -mabi=apcs-gnu -mlittle-endian
-mno-thumb-interwork -msoft-float -c
Choose “GCC C Linker of Tool Settings” tags, modify “Command” on right side to cross
compile toolchain we provided:
$(GCCPATH)gcc
Choose GCC Assembler of Tool Settings tag, modify cross compile toolchain we
provide in right side’s Command to :
$(GCCPATH)gcc
Here is used to configure compile options which is used when compiling assembly
file, usually application doesn’t use assembly language, so it is not need to configure.
There are some different settings for Eclipse between Linux and Windows, it due to
the path string in windows may conflict with Makefile. The ‘\’ and ‘:’ in windows path string
will lead eclipse failed to parse makefile, so we need change the ‘\’ and ‘:’ in other way.
The rule of translation below:
1. translate‘\’into‘/’in path string
2. translate‘DISK-LABEL:\’into‘/cygdrive/ DISK-LABEL/’
for example:
“E:\NEW8210\sdk\include” should translate into
“/cygdrive/e/NEW8210/sdk/include”
“C:\glibc-oabi-toolchain-arm-generic\bin\arm-unknown-linux-gnu-gcc” should
translate into
“/cygdrive/c/glibc-oabi-toolchain-arm-generic/bin/arm-unknown-linux-gnu-gcc”
4.5.7. Compile
Use command “Build Project” to compile an application, there are some methods to
execute this command:
Choose menu Project->Build Project
Choose project of Project Explorer, right click it, select Build Project command.
Default compile is Debug version, if you want to compile a Release version, you can
choose Build button on toolbar, then select Release.
If you want to compile again, choose Build Clean command, then choose Build
Project command, output information of compile is located at Console window of IDE
environment:
If some warnings/errors appear after compiled, the warnings/errors will locate at
Console window, at the same time, there will have obvious warning/error flags on project
of Project Explorer window.
NEW8210 have an application launcher, user’s application can run by this launcher,
it need developer to write a launch configuration, and add it to current user’s Desktop
folder (always locate at /home/admin/Desktop).
Filename is xxxxx.desktop
Content of file is some record entries.
Every line of file is a record entry.
There is 2 typies of record entry, one is section description, another is item
description.
Section description begins of “[”, and ends of “]”, between “[” and ”]” is key word
of section description.
Item description is a type of “key word = descripe the content”.
Now we use an example to declare the format of file. We build a launcher
configuration file, the file is saved as “/home/user0/Desktop/demo.desktop”, and file
content is below:
[Desktop Entry]
Type=Application
Version=0.0.1
Name= Demo program
Comment=NEW8210 Demo program
Icon=/home/user0/NEW8210demo/demo_logo_48.png
Exec=/home/user0/NEW8210demo/demo
Path=/home/user0/NEW8210demo
Terminal=false
In example above, section descriptor is “Desktop Entry”, it is fixed.
This file(demo.desktop) describes a application program(Type=Application).
The application version is “0.0.1”(Version=0.0.1).
The application displays the name of “demo program”(Name=demo program) on
application manager.
The application note message is “NEW8210 demo program”(Comment=NEW8210
demo program).
The application displays an icon of demo_logo_48.png
(Icon=/home/user0/NEW8210demo/demo_logo_48.png) on application manager.
If user want to execute this application program, user will execute the command:
/home/user0/NEW8210demo/demo(Exec=/home/user0/NEW8210demo/demo);
The application’s current path is: /home/user0/NEW8210demo
(Path=/home/user0/NEW8210demo).
The program doesn’t need to execute in Terminal (Terminal = false).
You also can use Console to run application, it can be used just when developing by
developer.
4.6. Debug program
NEW8210 use gdb to debug its program, we had installed gdbserver program on
NEW8210, so debugging program on NEW8210 is very convenient, and can undertake
remote debugging.
When debugging, you can use single-step debugging. If you know gdb command
well, you can debug by using gdb command directly, also can use other gdb front-end
tool, like DDD, insight, etc. Now we will introduce some methods about how to debug
program.
We had introduced how to create a Eclipse C Project above, now, we will modify C
Project source code, add a bug , then finding the bug by Eclipse.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
p = NULL;
*p = 0x12345678;
return *p;
}
After modified, compile application for Debug version, then download to NEW8210,
run it, program exit abnormity. Now we prepare to debug program, use debug method of
gdbserver + gdb, use tcp to remote debugging.
Firstly, you need connect NEW8210 with host PC by ethernet network, you can use
a switch to connect host PC with NEW8210, also can use a network cable to connect
host PC with NEW8210 directly. After connecting, configure developing PC IP and
NEW8210 IP, then they can visit each other, you can use ping command to achieve it.
For example, your host PC’s IP is 192.168.1.100, NEW8210’s IP is 192.168.1.200, then
you execute the command in host PC:
ping 192.168.1.200
If PC receives response, it means that they can visit each other, then you execute
the abnormally program just now on NEW8210, the method for execution is run program
in console. Now introduce about how to enter into NEW8210’s console: use ssh to login
to NEW8210 from host PC, execute command below:
ssh [email protected]
The user name can be: user0 or user1 … or user 15
Enter password: (if you do not know password, please contact us)
After complete, if you can see the command notes, that means it had entered into
console.
Switch to “Connection” tab page of Debugger, choose TCP of Type option, configure
NEW8210’s IP address to “Host name of IP address”, configure Port number to
2331(when run gdbserver command on NEW8210 above, wo choose gdbserver’s
listening port of 2331, make sure that gdbserver’s listening port is the same as here),
then click Debug button to debug, like picture below:
Now enter into the debug window, click Step Over (F6) to skip this sentence, click Step
into (F5) to enter into function implementation of this sentence, also can configure
breakpoint to debug, we will not introduce these debug methods here.Picture below is the
location when we executing the error language, it will notice error when clicking Step
Over, the problem of program is here:
Insight debugger is also a easy used gdb graphical front-end debugging, it also uses
gdb to debug, it has intuitive interface, and easy to use. This tool is a open source tool,
you can download it at http://sourceware.org/insight/downloads.php. If you want to debug
NEW8210 application program, we need to cross compile it. Here we don’t introduce how
to compile this tool, but how to make use of this tool.
Except of using GDB to debug application program, we also can find out the location
of exception from error message which is printed by kernel. This method needs
developer knows well about assembly language, it is fit to experienced developers.
Picture below is the error message printed by kernel when executing the exception
program:
[ 117.620000]
[ 117.620000] PC is at 0x8440
[ 117.620000] LR is at 0x8484
[ 117.620000] pc : [<00008440>] lr : [<00008484>] psr: 60000010
[ 117.620000] Flags: nZCv IRQs on FIQs on Mode USER_32 ISA ARM Segment user
[ 117.620000] r4:c1c88080
[ 117.620000] ffc0: 000084ac 00000000 00008310 00000000 00000000 00000000 40024000 be96fb30
These debug message can get by executing dmesg program. Form these error
message, we found that exception happened on USER_32 mode, it is application
program exception, if the mode is not USER_32, then it isn’t an application program
exception; you can also find that error program is DemoApp, the reason of exception
happen is “unhandled page fault(11) at 0x00000000”, PC point to 0x8440 when exception
happening, return address LR point to 0x8484, all the register’s value when exception
happening have been printed(R0~R10、SP、IP、FP、SPSR、LR、PC) , with these
information, we can find the location of error program by disassemble application
information.
/opt/compiler/glibc-oabi-toolchain-arm-generic/bin/arm-unknown-linux-gnu-objdump -D
DemoApp > DemoApp.asm
00008420 <bug_in_here>:
8420: e1a0c00d mov ip, sp
8424: e92dd800 push {fp, ip, lr, pc}
8428: e24cb004 sub fp, ip, #4 ; 0x4
842c: e24dd004 sub sp, sp, #4 ; 0x4
8430: e3a03000 mov r3, #0 ; 0x0
8434: e50b3010 str r3, [fp, #-16]
8438: e51b2010 ldr r2, [fp, #-16]
843c: e59f3010 ldr r3, [pc, #16] ; 8454 <bug_in_here+0x34>
8440: e5823000 str r3, [r2]
8444: e51b3010 ldr r3, [fp, #-16]
8448: e5933000 ldr r3, [r3]
844c: e1a00003 mov r0, r3
8450: e99da800 ldmib sp, {fp, sp, pc}
8454: 12345678 .word 0x12345678
If developers don’t know assemble language well, we can change assemble code to
C code. Just needing to add –S,--source option when disassembling: Intermix source
code with disassembly,command which is to disassembled is below:
/opt/compiler/glibc-oabi-toolchain-arm-generic/bin/arm-unknown-linux-gnu-objdump -DS
DemoApp > DemoApp.asm
00008420 <bug_in_here>:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
p = NULL;
8430: e3a03000 mov r3, #0 ; 0x0
8434: e50b3010 str r3, [fp, #-16]
*p = 0x12345678;
8438: e51b2010 ldr r2, [fp, #-16]
843c: e59f3010 ldr r3, [pc, #16] ; 8454 <bug_in_here+0x34>
8440: e5823000 str r3, [r2]
return *p;
8444: e51b3010 ldr r3, [fp, #-16]
8448: e5933000 ldr r3, [r3]
}
844c: e1a00003 mov r0, r3
8450: e99da800 ldmib sp, {fp, sp, pc}
8454: 12345678 .word 0x12345678
We have introduced 2 debugging methods, they are all debugging by GDB, but there
will have conditions that can not use GDB to debug:
If object program have been optimized, then source code will not correspond to
debugging location when debugging; if object program do not contains debugging
message, then gdb can’t know the location of source code, and of course can not
correspond to source code to debugging; if error code is in dynamic library, gdb can not
debug in dynamic library, because of dynamic library is dynamic linking, location of
linking is not fixed; if source code have some files that have the same filename, and they
are located in different folder, it may search the wrong source file when debugging.
5. API manual
API functions of this module was defined in the “posapi.h”; “libpos.so” must be used
when linking.
5.1.1. sys_reboot
5.1.2. sys_poweroff
5.1.3. sys_kbd_set
5.1.4. sys_kbd_get
5.1.5. sys_set_time
5.1.6. sys_get_status_bar_height
5.1.7. sys_delay_to_suspend
5.1.8. sys_suspend_now
5.1.9. sys_get_sn
Support: NEW8210
Notes:
5.1.10. beep
Support: NEW8210
Notes:
5.1.11. sys_backlight_set_time
=0 no backlight
<0 Backlight always on
Return: 0 Set OK
Others Other error code
Support: NEW8210
Notes: Once it is set up, the backlight will run according to the set value. But
after system reset, the set value of backlight will recover to its default
one..
5.1.12. sys_backlight_get_time
5.1.13. sys_get_machine_config
5.1.16. sys_get_hardware_config
5.1.17. sys_software_update
5.1.18. sys_battery_info
Buttons definition of NEW8210 complies with standard PC-101 keyboard, users can get
the same result by operating an external keyboard, or pressing key in NEW8210 directly.
When user pressing an key, system will send the key value of key, and the state value of
this key is state “press down”, after 400ms, system will send key value of this key again,
the state value of the key is also “press down”, And then every 44ms system will send the
key value and “press down” state value , until the key release. System send key value of
the key and state “release”. In other words, as long as key is pressed, system will send
key value and state of the key all the time, until key is released.
The correspondence of NEW8210’s keys and PC-101’s keys is listed as follow:
NEW8210 PC-101 Code Symbol
key key
0 0 KEY_0 0x0B DIKS_0 0x30
The Power key is not listed here, because NEW8210 application program can’t control
and get this key, while pressing power key for more than 1.5 s, system will be turned off
automatically.
In addition, on default condition it will start printer’s function of “paper skip” when pressing
feed key, application program can get the key value of the key.
5.3. Display
NEW8210 display based on the DirectFB library, the web site is http://www.directfb.org.
API documents link is http://www.directfb.org/docs/DirectFB_Refer _1_4/index.html.
The applications based on DirectFB have its own “Window”, DrectFB manage the
entire display windows, and so that each program is displayed on the LCD does not
interfere with other programs. Besides manage the display windows, DirectFB also
manages the input devices, the event buffer, fonts, graphics, audio/video, providing
users with a unified, friendly programming interface.
TTF/TTC
OTB(X11 bitmap font)
BDF(Bitmap Distribution Format)
JPEG
PNG
GIF
BMP
The formats of otb and bdf are point-array font library, the otb format is binary array
library, and the bdf format is text array library, these two formats can be converted to
each other, the file of bdf format is larger than that of otb format. No matter ttf library, or
otb, bdf font library, it is the same interface for external call, the programmer no need to
care for the different. Note: the ttf format is zoomable, but the otb and bdf formats unable
to do so, the size of them are fixed, if a not exist size is selected, it will not work.
5.3.1. DirectFB
5.3.1.1. Layers
It represents a separate image buffer. Most embedded devices have more than one
layer. Hardware using the appropriate alpha value for blending, then display.
5.3.1.2. Surface
A reserved area of memory used to store pixel data. The operation “drawing” and
“blitting” are ultimately act on the surfaces, the memory of surface can be obtained from
video memory, also can be obtained from system memory, which is determined by the
given limit.
It represents a particular layer of special surface of the frame buffer. If the primary
surface is single buffer, any operation on this main surface will be seen on screen.
The relationship between them is some one-to-one or one-to-many:
1 IDirectFB N Screens
1 Screen N Layers
1 Layer 1 Primary Surface
1 Layer N Windows
1 Window 1 Window Surface
1 Surface N Subsurface
Usually one screen has a display layer, but DFB support each of them have multiple
instances.
Each screen has one or more layers, typically, a screen only has one layer, but some
system support overlays, due to hardware support one layer display above on other
layers, there can be exist many layers.
Screen can not create window directly, but you can request a primary layer`s ID, and
request IDirectFB interface for your layer interface, then by this interface, you can create
a window.
Every window associating with a surface, the content drawn to the surface will not
display on the screen immediately, because the window manager will assembles all
surfaces to a main surface – based on the region to be freshened and the sequence of
stack.
Every layer associating with a surface, too. This surface is a direct manifestation to
the layer memory. In exclusive mode, you can only access to this surface, otherwise, you
can only create a window, then draw the surface by window manager.
……
exit_entry:
……
return ret;
}
First you should initialize the DirectFB, by calling the API DicectFBInit(), process the
input parameter, then by calling the API DirectFBCreate() to create a dfb object. Note:
this object should be released by calling API Release() to release the resource occupied
by it.
Above we described the relation about screen, layer, window and surface, they are
seemed complex, you can remember the rule for short: when custom displays, it`s only to
surface,and the drawing operations are also valid only for surface, no matter this surface
is created on layer directly, or got from a created window, or created from another
surface.
There are many methods to get surface, we recommend using the following
procedure:
DirectFBInit
DirectFBCreate(&dfb)
dfb->GetDisplayLayer(&layer)
layer->CreateWindow (&window)
window->GetSurface(&surface)
Sometimes we need to display a image on LCD, the DirectFB has already provides a
set of APIs, for the programmers, we offer the following code to display a image.
provider->GetSurfaceDescription(provider, &dsc);
dsc.flags = DSDESC_WIDTH | DSDESC_HEIGHT | DSDESC_PIXELFORMAT;
dsc.pixelformat = DSPF_ARGB;
if (dfb->CreateSurface(dfb, &dsc, &imgsurf) == DFB_OK)
provider->RenderTo(provider, imgsurf, NULL);
provider->Release(provider);
return imgsurf;
}
The code above used to load a image to a DirectFB`s surface, the image stored in
the surface memory, but it will not display on LCD. To display the image, another
operation is needed: IDirectFBSurface::Blit. To zoom for the image, you can use
IDirectFBSurface::stretchBlit, using the API IDirectFBSurface::TileBlit, you can magnify
the image to the full screen. Note: after these operations, if the surface with the image is
no longer be needed, you should call API Release() to release the resource, otherwise it
will lead to the leakage of memory.
libz.so
libfusion.so
libdirect.so
libdirectfb.so
When linking, please use command line: “-lz -lfusion -ldirect -ldirectfb”, and use “-L” to
index the path of these library.
5.4. Ped
API functions of this module was defined in the “ped.h”; “libped.so” must be used when
linking.
5.4.1. ped_get_random
5.4.2. ped_get_random_nr
5.4.3. ped_set_pin_input_region
5.4.4. ped_format
5.4.5. ped_clear_user_keys
5.4.6. ped_delete_key
Return: 0 Success
-1 Error. The error code please get from the global variable
errno.
Support: NEW8210
Notes:
5.4.7. ped_get_sensitive_timer
5.4.8. ped_set_pin_input_timeout
5.4.9. ped_get_dukpt_ksn
Support: NEW8210
Notes:
5.4.11. ped_write_pin_key_ex
5.4.12. ped_write_mac_key
5.4.13. ped_write_mac_key_ex
5.4.14. ped_write_master_key
5.4.15. ped_inject_pin_key
5.4.16. ped_inject_mac_key
5.4.17. ped_create_dukpt_key
5.4.18. ped_get_pin
Explain :
(1) ANSI X3.92 standard(Format EPS) as follow:
Data string format:”1234” + ISN [6bytes] + PIN[6bytes];
If PIN not enough 6 bytes, then fill ‘0’ with ahead.
Convert the string to BCD code, and use TPK as the key to TDEA.
(2) ANSI X9.8 standard(Format 0) as follow:
String 1 is “0000” with suffix of card number last 12 charters.
Convert string 1 to BCD bytes.
String 2 is PIN length [ASCII, 2bytes] + PIN [ASCII];
If string 2 not enough 16 bytes, add charter ‘F’ to the tail, and convert string 2 to BCD
bytes.
Use string 1 BCD XOR string 2 BCD then get 8 bytes number K, use TPK as TDEA key
to encrypt K, and then get the PIN_BLOCK.
5.4.19. ped_get_pin_fix
5.4.20. ped_get_pin_dukpt
5.4.21. ped_icc_offline_plain_pin
Name Value
C Control field 4 bit binary ‘0010’(hex. 2)
N PIN length 4 bit binary from ‘0010’ to ‘1100’ (hex form ‘4’ to
‘c’)
P PIN 4 bit binary from ‘0000’ to ‘1001’ (hex form ‘0’ to
‘9’)
P/F PIN/ pad bit Decided by PIN length
F Padding bit 4 bit binary ‘1111’(hex. ‘F’)
Note: PIN input is sensitive service, if the time between two PIN input
is too fast, the operation will be refused. So you can call
ped_get_sensitive_timer() to get current state, if the return value
large than 0(etc n), it means only after n seconds, you can inpuit PIN
again.
typedef struct {
uint32_t modlen; // The module length of PIN encryption public
key,
uint8_t mod[256]; // The module data of PIN encryption public
key,
uint32_t explen; // The exponet length of PIN encryption public
key,
uint8_t exp[4]; // The exponet data of PIN encryption public
key,
uint8_t iccrandom[8]; // The random data from ICC
} RsaPinKey_t;
5.4.22. ped_icc_offline_cipher_pin
Note: PIN input is sensitive service, if the time between two PIN input
is too fast, the operation will be refused. So you can call
ped_get_sensitive_timer() to get current state, if the return value
large than 0(etc n), it means only after n seconds, you can inpuit PIN
again.
K1
R1
K2
R1
K3
R3
Kn
Rn
We use first 8 bytes data (D1) as K1, and use the MAC key TDEA encrypt K1 get result R1.
R1 XOR with the second 8 bytes data (D2) then get the result K2. Use the MAC key TDEA
encrypt K2 get result R2…… and so on, the last Rn is the MAC result.
Algorithm 2:
When Len = 8, only use data to do one DES/3DES encrypt.
When Len > 8, we use the standard algorithm to encrypt MAC data. The algorithm as follow:
D1(8bytes) D2(8bytes) D3(8bytes) …… Dn(8bytes)
K2
K2
K2
Kn
MAC
EMV2000 Algorithm:
EMV2000 Algorithm is very like as Algorithm 1. If MAC key length is 8 bytes, that
EMV2000 Algorithm is same as Algorithm 1; If MAC key length is 16 bytes or 24 bytes, there are
some different, from the step 1 to the step n-1 are use 8bytes MAC key to encrypt data, and the
step n use 16 bytes or 24 bytes MAC key to encrypt data.
China UnionPay algorithm:
D1(8bytes) D2(8bytes) D3(8bytes) …… Dn(8bytes)
K2
K2
K2
Kn
R1
R2
Convert R2 to 16 ASCII
char
5.4.24. ped_get_mac_fix
5.4.25. ped_get_mac_dukpt
5.4.26. ped_inject_key_by_root
5.4.27. ped_get_config
API functions of this module was defined in the “epp.h”; “libepp.so” must be used when
linking.
enum EPP_ERROR_CODE
{
EPP_SUCCESS = 0,
EPP_RECV_PACKET_ERROR=2001,
EPP_PORT_OPEN_ERROR,
EPP_SEND_PACKET_ERROR, // 3
EPP_PACKET_LEN_ERROR,
EPP_RECV_TIMEOUT, // 5
EPP_PACKET_LEN_TOO_LONG,
EPP_CRC_CHECK_ERROR, // 7
EPP_OPEN_FILE_ERROR,
EPP_SEEK_FILE_ERROR, // 9
EPP_WRITE_FILE_ERROR,
EPP_READ_FILE_ERROR, // 11
EPP_CONFIGURE_INVALID,
EPP_CONFIGURE_MAC_ERROR, // 13
EPP_NO_PIN,
EPP_SEND_CMD_ERROR, // 15
EPP_RECV_CMD_ERROR,
EPP_RECV_RET_ERROR, // 17
EPP_RECV_LEN_ERROR,
EPP_MAC_CHECK_ERROR, // 19
EPP_AUTHEN_FAILED,
EPP_INPUT_PARAM_ERROR, // 21
EPP_USER_PRESS_CANCEL,
EPP_INPUT_CMD_ERROR, // 23
EPP_INPUT_KEY_INDEX_ERROR,
EPP_INPUT_MAC_LEN_ERROR, // 25
EPP_INPUT_MODE_ERROR,
EPP_KEY_TYPE_ERROR, // 27
EPP_KEY_INDEX_ERROR,
EPP_MASTER_KEY_INDEX_ERROR, // 29
EPP_BMP_ERROR,
EPP_PIN_CFG_LANGE_TYPE_ERROR, // 31
EPP_PIN_CFG_SYMBOL_TYPE_ERROR,
EPP_INPUT_DATA_LEN_ERROR, // 33
EPP_SET_PORT_ERROR,
EPP_CFG_ERROR, // 35
EPP_CLOSE_FAILED,
};
enum N20_RETURN_CODE{
RET_ERROR_BASE = 2300,
RET_PASSWORD_ERROR, // 1
RET_BOOT_LEN_ERROR,
RET_BOOT_HASH_ERROR, // 3
RET_BOOT_MAC_ERROR,
RET_NOT_UBSK, // 5
RET_CHECK_UBSK_FAILED,
RET_CHECK_KSK_FAILED, // 7
RET_NOT_LCK,
RET_NOT_AUTH, // 9
RET_NOT_LOGON,
RET_RECV_FAILED, // 11
RET_AUTH_CHECK_FAILED,
RET_MAC_CHECK_FAILED, // 13
RET_CRC_CHECK_ERROR,
RET_KVC_CHECK_ERROR, // 15
RET_NOT_APP_FREE_SPACE,
RET_APP_NOT_EXIST, // 17
RET_KEY_TYPE_ERROR,
RET_KEY_TYPE_NOT_SUPPORT, // 19
RET_MAC_LEN_ERROR,
RET_MAIN_KEY_INDEX_ERROR, // 21
RET_MAIN_KEY_NOT_EXIST,
RET_KEY_INDEX_ERROR, // 23
RET_KEY_LEN_ERROR,
RET_KEY_BE_USE, // 25
RET_MAIN_KEY_BE_USE, // 26
RET_MAC_ALG_MODE_ERROR,
RET_KEY_GET_ERROR,
RET_KEY_OVER_FLOW, // 29
RET_KEY_SAME_ERROR,
RET_KEY_NOT_EXIST, // 31
RET_KEY_MAC_CHECK_FAILED,
RET_KEY_KSN_LEN_ERROR, // 33
RET_KEY_BDK_LEN_ERROR,
RET_USER_PRESS_CANCEL_EXIT, // 35
RET_USER_INPUT_TIME_OUT,
RET_KSN_LEN_RERROR, // 37
RET_APP_NUM_OVER_FLOW,
RET_RW_LENGTH_ERROR, // 39
RET_PIN_KEY_TIME_LOCK,
RET_MAC_KEY_TIME_LOCK, // 41
RET_SET_PIN_TIME_OUT_ERROR,
RET_WRITE_EEPROM_FAILED, // 43
RET_RECV_LEN_ERROR,
RET_PARAM_ERROR // 45
};
typedef struct {
BYTE AppName[32];
BYTE Lck[16];
BYTE Mtek[24];
BYTE Akdak[16];
BYTE Akuak[16];
BYTE Mdtek[24];
BYTE Mutek[24];
} EppAuthKey_t; // 152 bytes
5.5.2. module structure
typedef struct {
BYTE KeyType; /* key type
0x01:master key;
0x02:MAC key;
0x03:PIN key;
0x10:Fixed MAC key;
0x11:Fixed PIN key; */
BYTE Mode;/*
Bit0~3 TDEA_DECRYPT 0x00 use decryption method to get expressly
target key
TDEA_NONE 0x02 write into expressly target key directly(is
invalid to MAC key and PIN key)
Bit4~7 PARITY_NONE 0x00 no check on the (decrypted) Key express
PARITY_ODD 0x10 odd parity on the (decrypted) key express
PARITY_EVEN 0x20 even parity on the (decrypted) key
express*/
BYTE KeyLen; // length of key, valid values is 8/16/24
BYTE KeyIndex; // Key Index[1,100]
BYTE MasterKeyIndex; /*master key index[1,100], this parameter is valid just when
key type is MAC key or PIN key*/
BYTE KeyData[24]; // content of key
} EppAppKey_t;
5.5.3. epp_open
5.5.4. epp_close
5.5.5. epp_init
5.5.6. epp_download_lck_mtek
5.5.7. epp_download_aik
5.5.8. epp_download_appkey
5.5.9. epp_download_dukpt_key
5.5.10. epp_get_mac
encryption
encryption
encryption
encryption
MAC
First 8 bytes do DES/3DES encryption one time, the result will do xor with
next set of data(8 bytes), and do DES/3DES encryption one time again,…after
the final set of data have done one DES/3DES encryption,get MAC operation
result(8 bytes).
Algorithm 2:
If Len = 8, do DES/3DES encryption operation on Data one time.
If Len > 8, do standard MAC encryption operation on data, algorithm as
shown:
8bytes(start) 8bytes 8bytes …… 8bytes(end)
encryption
MAC
encryption
encryption
5.5.11. epp_get_pin
5.5.12. epp_get_tdea
5.5.13. epp_set_pin_input_timeout
5.5.14. epp_set_tdes_iv
5.5.15. epp_get_rand
5.5.16. epp_clear_key
5.5.18. epp_format_ped
5.5.19. epp_set_idle_logo
5.5.21. epp_display_logo
5.5.22. epp_display_string
5.5.23. epp_clear_screen
5.5.24. epp_get_system_info
5.5.25. epp_beep
5.5.26. epp_light
5.5.27. epp_kb_get_string
In the blocking mode, when the program writing printed data into the printer, if the
printer internal print buffer is full, then the application writes data to the printer's
operation will block until the printer will have printed some data, there is room for
internal buffer blocked when the operation will be re-awakened, continue to write
data.
In the non-blocking mode, when the program will write the data to be printed in the
printer, if the printer internal print buffer is full, then the application writes data to the
printer’s operation will immediately failure and returns, and without blocking.
Print module just provide the lattice data will be printed to print, as to how to populate
the lattice data, self-completed by the developer, the printer is a shared device,
different applications can open the device and print at the same time, thus may
cause the print data confusion, so the developers should open the device to operate
only when it is need to call, when the operation is complete the device should be
closed immediately.
API functions of this module was defined in the “printer.h”, “posapi.h”; “libpos.so” must be
used when linking.
5.6.1. printer_open
5.6.2. printer_close
5.6.3. printer_read
5.6.4. printer_write
5.6.5. printer_get_status
5.6.6. printer_get_param
5.6.8. printer_feed_start
5.6.9. printer_feed_stop
5.6.10. printer_reset
5.6.11. print_surface
In the blocking mode, when the program calling to read magnetic card data , if the
magnetic stripe reader has no data, then the application will block until user swipes
card, when magnetic card module received data the blocked program will be re-
awakened, application will get data from magnetic card module.
In the non-blocking mode, when the program calling to read magnetic card data , if the
magnetic stripe reader has no data, the application will not be blocked ,calling the
magstripe_read will leads to error and returns immediately.(not the fault of magnetic card
module)
For the convenience of developer, we also provide read and write function with
timeout, if the reader can not read and write data at a set period of time, function will
exit.
API functions of this module was defined in the “magstripe.h”; “libpos.so” must be used
when linking.
5.7.1. magstripe_open
5.7.2. magstripe_close
5.7.3. magstripe_read
5.7.4. magstripe_read_timeout
ms timeout time,unit:ms
Return: >0 number of data bytes from magnetic stripe reader
-ETIME read timeout
others other error code
Support: NEW8210
Notes:
5.7.5. magstripe_write
5.7.6. magstripe_write_timeout
5.7.8. magstripe_set_trackset
NEW8210 support one user card slot and three PSAM card slots currently, corresponding
card slot device name are listed as follow:
“/dev/usercard” ----- user card slot
“/dev/samcard1” ------ PSAM1 card slot
“/dev/samcard2” ------ PSAM2 card slot
“/dev/samcard3” ------ PSAM3 card slot
Above them PSAM card slot just supports T=0 、 T=1 asynchronous operation of CPU
card, and user card not only supports T=0、T=1 asynchronous operation of CPU card, but
also supports various synchronization card, such as SLE4428、SLE4442 and AT24 series
memory card.
When developing application, please includes iccard.h 、 sle4442.h 、 sle4428.h and
at24xx.h。
Please link to libiccard.so lib file when compiling.
5.8.1. iccard_open_cardslot
5.8.3. iccard_check_card_in_slot
5.8.4. iccard_power_up
Prototype int iccard_power_up(int fd, int vcc, int mode, int *len, void *atr)
:
Function: power on and reset asynchronous CPU card of IC card slot when
contacting
Parameter: fd opened device file number that iccard_open_cardslot
function returns
vcc IC card working voltage, the value is below:
CVCC_1_8_VOLT 1.8v operation
CVCC_3_VOLT 3v operation
CVCC_5_VOLT 5v operation
mode IC card working mode, the value is below:
EMV_MODE ------ EMV working mode
ISO_MODE ----- ISO7816 , 9600BPS working
mode(supports PPS protocol)
ISO_19200 ------ ISO7816 , 19200BPS working
mode
ISO_38400 ------ ISO7816 , 38400BPS working
mode
len ( outp ATR length that IC card returns
ut)
atr(outpu ATR information that IC card returns
t)
Return: 0 power on and reset IC card success
-1 Power on card failure, please get actual error value by
errno
ENXIO : is not IC card exist in card slot
EINVAL : input parameter error
ECOMM : IC card return data parity error or LRC
parity error
EPROTO : IC card return data does not meet the
EMV standard or ISO7816 standard
ETIME : timeout and no return
Other value :other error code
Support: NEW8210
Notes: 1、Please refer to iccard.h。
5.8.5. iccard_exchange_apdu
5.8.6. iccard_power_down
5.9.1. sle4428_open
5.9.2. sle4428_close
5.9.3. sle4428_read
Support: NEW8210
Notes: 1、Please refer to sle4428.h。
5.9.4. sle4428_read_error_count
5.9.5. sle4428_verify_pwd
5.9.6. sle4428_change_key
5.9.7. sle4428_lock
5.9.8. sle4428_read_status
5.9.9. sle4428_write
5.9.10. sle4428_write_protect
5.9.11. sle4428_check_data
5.10.1. sle4442_open
5.10.2. sle4442_close
5.10.3. sle4442_verify
5.10.4. sle4442_read_error_count
5.10.5. sle4442_change_key
5.10.6. sle4442_lock
5.10.7. sle4442_read
5.10.8. sle4442_write
5.10.9. sle4442_read_status
5.10.10. sle4442_check_data
5.11.1.1. mif_open
5.11.1.2. mif_close
5.11.1.4. mif_get_timeout
5.11.1.5. iso14443_delay_etu
5.11.1.6. iso14443_reset_picc
Return: 0 Success
-1 Operate failure, please get the actual error code by errno:
EINVAL : input parameter error
Other value : other error code
Support: NEW8210
Notes: Please refer to iso14443.h。
5.11.1.7. mif_select_carrier_type
5.11.1.8. iso14443_ReqA
5.11.1.9. iso14443_WupA
5.11.1.10. iso14443_Anticollision
5.11.1.11. iso14443_Select
Prototype int iso14443_Select(int fd,uint8_t sel, const void *uid, uint8_t *sak)
:
Function: Select the TypeA card
Parameter: fd opened device file number that mif_open function
returns
sel Choose layer:
0x93 ------ first level
0x95 ------ second level
0x97 ------ third level
uid this level UID information of card, 4 bytes
sak ( output card returned confirmation, 1 byte
)
Return: 0 operate OK
-1 Operate failure, please get the actual error code by
errno:
EINVAL : input parameter error
EIO : read card chip error
ECOMM : Parity error or CRC check error of card
returned data
EPROTO :Card doesn’t fix ISO14443 standard
EBADE : error of length of card returned data
ETIME : timeout and no return
EMULTIHOP : more than one card exists in
induction zone
other value : other error code
Support: NEW8210
Notes: Please refer to iso14443.h。
5.11.1.12. Iso1443_get_typeA_uid
Return: 0 Success
-1 Operate failure, please get the actual error code by errno:
EINVAL : input parameter error
other value : other error code
Support: NEW8210
Notes: Please refer to iso14443.h。
5.11.1.13. Iso1443_get_cardtype
Return: 0 Success
- Operate failure, please get the actual error code by errno:
1 EINVAL : input parameter error
other value : other error code
Support: NEW8210
Notes: Please refer to iso14443.h。
5.11.1.14. iso14443_HaltA
5.11.1.15. iso14443_RATS
5.11.1.16. iso14443_PPS
5.11.1.17. iso14443_ReqB
5.11.1.18. iso14443_WupB
5.11.1.19. iso14443_SlotMarker
5.11.1.21. iso14443_HaltB
5.11.1.22. iso14443_tcl_poll
5.11.1.23. iso14443_tcl_active
5.11.1.24. iso14443_tcl_exchange
5.11.1.25. iso14443_tcl_deactive
5.11.1.26. iso14443_no_tcl_exchange
5.11.1.27. mif_check_multi_card
5.11.1.28. felica_exchange
5.11.1.29. emv_contactless_active
5.11.1.30. emv_contactless_deactive_picc
5.11.1.31. emv_contactless_obtain_status
5.11.1.32. emv_contactless_get_lasterror
5.11.1.33. emv_contactless_exchange_apdu
5.11.1.34. compat_InATR
5.11.1.35. compat_InPSL
5.11.1.36. Compat_InListPassiveTarget
5.11.1.37. compat_InDataExchange
Return: 0 Success
-1 Operate failure, please get the actual error code by errno:
ENODATA : no card exists in inductive zone
EMULTIHOP : exists multiple cards in inductive card
EPROTO : Card doesn’t comply with ISO14443
standard
EBADE : error of length of card returned data
other value : other error code
Support: NEW8210
Notes: Please Refer iso14443.h
5.11.1.39. compat_mifCheckOnlyOneCard
5.11.2.1. mifare_one_poll
5.11.2.3. mifare_one_authenticate
5.11.2.4. mifare_one_read_block
5.11.2.5. mifare_one_write_block
5.11.2.6. mifare_one_set_value
5.11.2.7. mifare_one_increment
5.11.2.8. mifare_one_decrement
5.11.2.9. mifare_one_restore
5.11.2.10. mifare_one_transfer
5.11.2.11. mifare_one_get_value
5.11.3.1. mifare_ultralight_poll
5.11.3.2. mifare_ultralight_halt
5.11.3.3. mifare_ultralight_read_page
5.11.3.4. mifare_ultralight_write_page
5.11.3.5. mifare_ultralight_write_page16
5.11.4.1. desfire_poll
5.11.4.2. desfire_deactive
5.11.4.4. desfire_authenticate_iso
5.11.4.5. desfire_authenticate_aes
5.11.4.6. desfire_change_key_settings
5.11.4.8. desfire_change_picc_masterkey
5.11.4.9. desfire_change_app_key
5.11.4.10. desfire_get_key_version
5.11.4.12. desfire_delete_application
5.11.4.13. desfire_get_application_ids
5.11.4.14. desfire_get_dfnames
5.11.4.15. desfire_select_application
5.11.4.16. desfire_format_picc
5.11.4.18. desfire_set_configuration
5.11.4.19. desfire_free_memory
5.11.4.21. desfire_get_fids
5.11.4.22. desfire_get_iso_fids
5.11.4.23. desfire_get_filesetting
5.11.4.24. desfire_change_filesetting
5.11.4.26. desfire_create_backup_datafile
5.11.4.27. desfire_create_valuefile
5.11.4.28. desfire_create_linear_recordfile
5.11.4.29. desfire_create_cyclic_recordfile
5.11.4.30. desfire_delete_file
5.11.4.31. desfire_read_data
5.11.4.32. desfire_write_data
5.11.4.33. desfire_get_value
5.11.4.34. desfire_credit
5.11.4.35. desfire_debit
5.11.4.36. desfire_limited_credit
5.11.4.37. desfire_write_record
5.11.4.38. desfire_read_records
5.11.4.39. desfire_clear_recordfile
5.11.4.41. desfire_abort_transaction
5.12.1. at24_open
5.12.2. at24_read
5.12.4. at24_close
5.13. Modem
Modem supports 1200bps and 2400bps sync dial, supports up to 336000bps async dial,
supports ppp dial.
Please refer to PPPLogin, PPPLogout and PPPCheck to get the information for ppp
dial.
The following introduce the sync dial and async dial.
Modem status
Definition Description
MODEM_STATE_NOT_INIT Modem has not been initialized, or Initialized
failed. If initialized successfully, modem will turn to
MODEM_STATE_NO_SET_MODE automatically.
MODEM_STATE_NO_SET_MODE Modem has been initialized successfully, but the
mode has not been set. At this state, application is
permitted to set dial parameters. If the parameters
are set successfully, modem will turn to
MODEM_STATE_DISCONNECT.
MODEM_STATE_SYNC_MODE The background is handling after the mode is set
to sync dial. If handled successfully, modem will
turn to MODEM_STATE_DISCONNECT
automatically.
MODEM_STATE_ASYN_MODE The background is handling after the mode is set
to async dial. If handled successfully, modem will
turn to MODEM_STATE_DISCONNECT
automatically.
MODEM_STATE_DISCONNECT Modem is disconnected. In this state, application
is permitted to dial, set dial parameters, set sdlc
parameters or dial off.
MODEM_STATE_WAITTING Modem turns to dial in state, waiting for dial in. At
this state, modem can return to
MODEM_STATE_DISCONNECT via dial off or exit
dial in mode.
MODEM_STATE_DAILING Modem is dialing. If dials successfully, modem
turns to MODEM_STATE_CONNECT_SDLC
(sync mode), or turns to
MODEM_STATE_CONNECT (async mode)
directly. Modem can return to
MODEM_STATE_DISCONNECT via dial off.
MODEM_STATE_CONNECT_SDLC Modem connects successfully, and the sldc is
handshaking. If handshakes successfully, modem
will turn to MODEM_STATE_CONNECT,
otherwise, it will turn to
MODEM_STATE_DISCONNECT.
MODEM_STATE_CONNECT The data link is connected successfully.
Application is permitted to send/receive data in
this state. If dials off, modem will return to
MODEM_STATE_DISCONNECT.
Modem state transition diagram:
Dial modes:
Definition Description
MODEM_DAIL_DTMF DTMF mode
MODEM_DAIL_PULSE PULSE mode
typedef struct {
int connect_mode;
int connect_speed;
int dial_mode;
int dial_pause;
int dial_timeo;
int idle_timeo;
int extension_chk;
RegionCode_t region;
int reserved[4];
} ModemDialParms_t;
This structure is used to set modem dial parameters. The member is defined as
following:
connect_mode: MODEM_COMM_ASYNC / MODEM_COMM_SYNC
connect_speed: Point out the expected speed, refer to the definition
dial_mode: MODEM_DAIL_DTMF / MODEM_DAIL_PULSE
dial_pause: pause time if there is ‘,’ in the dial number string (unit: second)
dial_timeo: Set the timeout of dial (unit: second)
idle_timeo: Timeout of idle. When there is no data send/receive in set timeout, modem
will dial off automatically. Set to 0 disable idle detect.
extension_chk: 1-check whether the extension phone is in use before dial; 0-don’t check
region: Country code IDs, in different countries or regions, the modulability of
telephone line may be different too, so you should set country code in
here.
reserved: set to 0
This structure is used to set/get SDLC parameters. The incorrect setting will lead the
protocol works abnormally. If you don’t know the protocol clearly, please don’t use this
function.
5.13.3. modem_open
Example: Example 1:
int fd;
if ((fd = modem_open(“/dev/ttyS1”, O_RDWR)) < 0) {
// error
}
Example 2:
if ((fd = modem_open(“/dev/ttyS1”, O_RDWR | O_NONBLOCK)) < 0) {
// error
}
5.13.4. modem_close
5.13.5. modem_write
5.13.7. modem_wait_until_sent
5.13.8. modem_read
5.13.9. modem_read_timeout
5.13.10. modem_dialing
5.13.11. modem_hangup
5.13.12. modem_get_status
while (1) {
if ((retval = modem_get_status(fd, &status)))
break;
return retval;
}
5.13.13. modem_get_last_errno
5.13.15. modem_get_dial_parms
5.13.17. modem_set_sdlc_parms
5.13.18. modem_enter_auto_answer
Return: 0 Success
Other Failed,Please refer <errno.h>
Support: NEW8210
Notes:
5.13.19. modem_exit_auto_answer
5.13.20. modem_check_extension
return retval;
}
return retval;
}
5.13.22. modem_power_control
5.14. PPP
5.14.1. ppp_open
wnet_moduleinfo_t modinfo;
memset(&modinfo, 0, sizeof(wnet_moduleinfo_t));
If (wnet_getmodinfo(&modinfo)) {
// 错误处理
}
......
Retval = ppp_open(modinfo.Pppdev, gprs_chat_file, “card”, “card”,
PPP_ALG_PAP, 45);
......
5.14.2. ppp_close
5.14.3. ppp_check
5.14.4. ppp_set_dns
5.15. GPRS/CDMA
//for phone
#define WET_EMERGENCY_ERR (-5012) // SIM/UIM is in emergency status
#define WET_RING_ERR (-5013) // detect ringing
#define WET_BUSY_ERR (-5014) // detect call in progress
#define WET_DIALING_ERR (-5015) // dialing
#define WET_PPP_INVALID_ERR (-5016) // ppp connect disable
5.15.2. Structure
typedef struct{
int arfcn;
int rxlev;
int bsic;
int cell_id;
int lac;
int mnc;
int mcc;
int aiRev[5];
}tBaseStationGPRS;
typedef struct{
int BandClass;
int Channel;
int SID;
int NID;
int BaseStationPRev;
int PilotPNoffset;
int BaseStationID;
int SlotCycleIndex;
int RawEcIo;
int RxPower;
int TxPower;
int TxAdj;
}tBaseStationCDMA;
typedef struct{
int iFlag; // 1:GPRS, 2:CDMA
union{
tBaseStationGPRS oGprs;
tBaseStationCDMA oCdma;
} Wnet;
}tBaseStation;
typedef struct{
unsigned char byLength; // number length
unsigned char byType; // type,0x91:international, 0x81:Inland
unsigned char abyNumber[30]; // number content
}tTelInfo;
typedef struct{
char strSca[64]; // server central tel number
char strDstAddr[64]; // Destination address
unsigned char byPid; // Protocol ID, the default value is 0x00
unsigned char byDcs; // Decord Standard
unsigned char byUniqueID; // Decord Standard
unsigned char byTpVp; // SMS Validity Period
unsigned char abyPduType[MAX_SMS_NUMBER]; // PDU type
int aiContentLength[MAX_SMS_NUMBER]; // the length of sms content
int aiCompressLength[MAX_SMS_NUMBER]; // the length of sms content
char strContentData[MAX_SMS_NUMBER*PDU_SMS_CONTENT_LENGTH]; //
the content of sms
unsigned char abyRev[24]; //
}tPduSmsSend;
typedef struct{
int index; // the index in the sms memory
char strScts[16]; // the time of sms server, like "12032718250032" --- 2012-03-27
18:25:00 32
char strSca[64]; // server central tel number
char strOa[64]; // Orient address
unsigned char byStatus; // 0:"REC UNREAD", 1:"REC READ", 2:"STO UNSENT",
3:"STO SENT", 4:"ALL"
unsigned char byPduType; // PDU type
unsigned char byPid; // Protocol ID
unsigned char byDcs; // Decord Standard
int iContentLength; // the length of sms content
char strContentData[336]; // the content of sms
}tPduSmsRecv;
typedef struct{
int index; // the index in the sms memory
unsigned char abyTime[8]; // the time of sms server, format:YYMMDDHHMMSSZZ, ZZ
is zone
// like "\x12\x03\x27\x18\x25\x00\x32\x00" --- 2012-03-27 18:25:00 32
tTelInfo oSca; // server central tel number
tTelInfo oOa; // Orient address
// Such as "\x05\x10\x08\x6F"---->"10086"
// Such as "\x0d\x86\x18\x92\x84\x84\x80\x8f"---->"8618928484808"
unsigned char byStatus; // 0:"REC UNREAD", 1:"REC READ", 2:"STO UNSENT",
3:"STO SENT", 4:"ALL"
unsigned char byCurItem; // From 0 to TotalNum-1
unsigned char byTotalNum; // TotalNum >= 1
unsigned char byDecodeStandard;// 0x00:ASCII; 0x08:UCS2(UNICODE 16); 0x04:Hex
data
int iSmsLength; // the length of sms content
unsigned char abyUniqueID[2]; // SMS unique ID
char stSmsData[170]; // the content of sms
}tSmsRecv; // 256 bytes
typedef struct{
tTelInfo oSca; // server central tel number
tTelInfo oDstAddr;
int iSmsLength; // the length of sms content
unsigned char abySmsData[3080]; // the content of sms
// ASCII Maxin length 3060 bytes
// UCS2 Maxin length 2680 bytes
// Hex Maxin length 2680 bytes
5.15.3. wnet_power_on
5.15.4. wnet_power_down
5.15.5. wnet_init
5.15.6. wnet_reset
5.15.8. wnet_signal
5.15.9. wnet_checksim
5.15.10. wnet_getimei
5.15.11. wnet_getmodinfo
5.15.13. wnet_sms_send
5.15.14. wnet_sms_read
5.15.15. wnet_sms_delete
5.15.16. wnet_phone_status
5.15.17. wnet_phone_answer
5.15.18. wnet_phone_hangup
5.15.19. wnet_phone_call
5.15.21. wnet_get_neighbourbasestation_info
5.15.22. wnet_read_simcardID
5.15.23. wnet_read_simcardIMSI
5.15.24. wnet_get_current_sim
5.15.25. wnet_select_sim
int simno;
……
simno = wnet_get_current_sim();
if (simno < 0)
report_error();
else {
simno ^= 1;
wnet_power_down();
if (wnet_select_sim(simno))
report_error();
}
……
Notice: If the terminal is not the Dual-SIM version, call this function has no
effect, it always operate the same SIM card.
5.16.1. bar_open
Example 2:
if ((fd = bar_open(“/dev/ttyS2”, O_RDONLY | O_NONBLOCK)) < 0) {
// error
}
5.16.2. bar_close
5.16.3. bar_scan
5.16.4. bar_read
5.16.5. bar_read_timeout
5.17. VPDN
API functions of this module was defined in the “vpdn.h”; “libvpdn.so” must be used when
linking.
typedef enum {
VPDN_NO_ERROR, /* vpdn dial successfully,connection to server is established
*/
VPDN_IS_CONNECTING, /* vpdn dial is on the way */
VPDN_IS_DISCONNECTED, /* vpdn connection to server is disconnected */
VPDN_ERROR, /* other error */
VPDN_CERT_FILE_UNAVAILABLE, /* vpdn certification file is unavailable */
VPDN_NO_DEFAULT_ROUTE, /* no default route to vpdn server */
} RESULT_ERROR_ENUM;
5.17.1. vpdn_open
5.17.2. vpdn_close
5.17.3. vpdn_call_pptp
typedef struct {
} pptp_arg_t;
func The function which will be called when the dialing result is sent back by
typedef struct {
int intf_is_up; /* vpdn interface status ,TRUE for up, FALSE for
down */
} result_arg_t;
Return: 0 OK
other Failed, refer to <errno.h>
Be NEW8210
Applicable
In:
Notes: The result_notify_func will be call again if vpdn dial connection is
disconnected or the status of vpdn interface is changed.
There must be a default route to vpdn server before dialing vpdn. A
default route may be generate by ethernet or GPRS, but no China
Mobile’s GPRS network.
Default route will be changed to vpdn network after dialing vpdn
successfully.
Example:
5.17.4. vpdn_call_l2tp_psk
typedef struct {
struct in_addr server; /* vpdn server ip address */
} l2tp_psk_arg_t;
5.17.5. vpdn_call_l2tp_cert
char domain[32]; /* domain may be need if the vpdn server is a windows OS.
1) cacert.pem
2) vpnclient_cert.pem, vpnclient_key.pem,
3) vpngateway_cert.pem, vpngateway_key.pem */
} l2tp_cert_arg_t;
func The function which will be called when the dialing result is
sent back by vpdn manager process.
Usage for the function is descripted in vpdn_call_pptp(locate
at 240)
Return: 0 OK
other Failed, refer to <errno.h>
Be NEW8210
Applicable
In:
Notes: IPSec certificate encryption has a Official name X.509. Sometimes it is
called RSA. Actually X.509 is based on RSA.
The user need to offer root CA, local CA and server CA , see
l2tp_cert_arg_t for detail.
The result_notify_func will be call again if vpdn dial connection is
disconnected or the status of vpdn interface is changed.
There must be a default route to vpdn server before dialing vpdn. A
default route may be generate by ethernet or GPRS.
Default route will be changed to vpdn network after dialing vpdn
successfully.
Example:
5.17.6. vpdn_disconnect
6.1. tty_property_config
Prototype: int tty_property_config(int fd, int baudrate, int databits, int parity, int
stopbits, int flow)
Function: Uart parameter setting
Parameter: ifd Uart file handle
baudrate Baud rate
databits Bits
parity Parity
stopbits Stop bits
flow flow
Return:
Support: NEW8210/NEW8110P
Notes:
7. Network Program
Socket TCP/IP
Please refer linux network program documents
ssl
Please refer openssl documents.
8. File Access