Wavecom GR64, GS64 Application Note

GR/GS64 APPLICATION NOTE
Embedded Application Remote Download
Reference: WI_DEV_Gx64_APN_012
Version: 001
Date: February 26, 2007
Trademarks
®, WAVECOM®, WISMO®, Open AT®, Wireless CPU®, Wireless Microprocessor® and certain other trademarks and logos appearing on this document, are filed or registered trademarks of Wavecom S.A. in France or in other countries. All other company and/or product names mentioned may be filed or registered trademarks of their respective owners.
Copyright
This manual is copyrighted by WAVECOM with all rights reserved. No part of this manual may be reproduced in any form without the prior written permission of WAVECOM.
No patent liability is assumed with respect to the use of the information contained herein.
No Warranty
WAVECOM publishes this manual without making any warranty as to the content contained herein. Further Wavecom Inc reserves the right to make modifications, additions and deletions to this manual due to typographical errors, inaccurate information, or improvements to programs and/or equipment at any time and without notice. Such changes will, nevertheless be incorporated into new editions of this manual.
Gx64 APPLICATION NOTE EA Remote Download Page: 2/22
This document is the sole and exclusive property of WAVECOM. Not to be distributed or divulged without prior written agreement. Ce document est la propriété exclusive de WAVECOM. Il ne peut être communiqué ou divulgué à des tiers sans son autorisation préalable
Table of Contents
1 Introduction.......................................................................................... 5
2 Overview............................................................................................... 6
2.1 GENERAL ............................................................................................................... 6
2.2 CONTROL PC SETUP ............................................................................................... 6
2.3 REMOTE GR64 SETUP ............................................................................................. 7
2.4 SECURITY ASPECTS................................................................................................. 7
2.4.1 SMS METHOD ................................................................................................. 7
2.4.2 CLIP METHOD................................................................................................. 8
2.4.3 IP ADDRESS METHOD...................................................................................... 8
3 Functional Description of Embedded Application .................................. 9
3.1 FLOW CHART OF REMOTE CONTROL EMBEDDED APPLICATION................................ 9
3.1.1 RC DESCRIPTION .......................................................................................... 10
3.2 IPRC EMBEDDED APPLICATION CODE.................................................................... 12
Appendix A............................................................................................... 14
SCRIPT DOWNLOAD SEQUENCE ..................................................................................... 14
XMODEM BLOCK STRUCTURE ........................................................................................ 15
SCRIPT HEADER BLOCK ................................................................................................. 15
Appendix B ............................................................................................... 16
REMOTE DOWNLOAD APPLICATION ............................................................................... 16
TCP/IP CONTROLS ...................................................................................................... 17
SERIAL CONTROLS ...................................................................................................... 17
COMMON CONTROLS.................................................................................................. 17
4 Appendix C......................................................................................... 19
Gx64 APPLICATION NOTE EA Remote Download Page: 3/22
This document is the sole and exclusive property of WAVECOM. Not to be distributed or divulged without prior written agreement. Ce document est la propriété exclusive de WAVECOM. Il ne peut être communiqué ou divulgué à des tiers sans son autorisation préalable
REMOTE DOWNLOAD APPLICATION VIA M2MPOWER IDE ................................................ 19
Gx64 APPLICATION NOTE EA Remote Download Page: 4/22
This document is the sole and exclusive property of WAVECOM. Not to be distributed or divulged without prior written agreement. Ce document est la propriété exclusive de WAVECOM. Il ne peut être communiqué ou divulgué à des tiers sans son autorisation préalable

1 Introduction

The GR64 has been designed so that scripts embedded within the device can be updated either through a serial interface on UART1 or where this is not feasible, due to location, remotely using the air interface. The script resident in the device must be written in a way that makes remote access permissible and preferably with some form of authentication of the calling party.
Gx64 APPLICATION NOTE EA Remote Download Page: 5/22
This document is the sole and exclusive property of WAVECOM. Not to be distributed or divulged without prior written agreement. Ce document est la propriété exclusive de WAVECOM. Il ne peut être communiqué ou divulgué à des tiers sans son autorisation préalable

2 Overview

2.1 General

The remote script download is dependant on the currently active script within the GR64 having the remote control (RC/IPRC) intrinsic function capability written in such a way that once a connection is made (circuit switch data call or IP connection), the remote control (RC/IPRC) intrinsic function is called and the remote script download takes place. Once the script is downloaded into GR64 memory and all checksums are verified, the GR64 is reset, and on completion of the power up routine, the new downloaded script is activated.
It is imperative that the new script downloaded using the over the air routine also has the RC/IPRC functionality written into it. If not, once this new script is activated and running, this script cannot be updated again.
The remote download process takes care of script number allocation and will use whatever script number is not being used by the activated script. This ensures that the original script is not lost and can be activated again if the new script is not functioning as expected.
Note: It is very important that the new script to be downloaded using the remote download facility has been checked thoroughly for possible bugs or run time errors. As once the script is downloaded and activated, it is not possible to gain remote access again if the script has crashed and is not running.

2.2 Control PC setup

The user has two alternative methods available to assist in the remote download of embedded application scripts. Firstly they can access the functionality via the
m
power IDE (Directions for its use can be found in Appendix C), secondly the
M2 user can use the Remote Download Application.
If using the Remote Download Application, the host PC requires Microsoft .NET framework 2.0 to run the application. This Remote Download Application provides connectivity to the remote module either through TCP/IP in the form of a host PC Winsock or CSD using a GSM modem connected to a serial port. The Download Sequence is as follows:
Gx64 APPLICATION NOTE EA Remote Download Page: 6/22
1. Select connection type, TCP/IP or CSD (serial).
2. Establish connection to remote module.
3. Select download slot.
This document is the sole and exclusive property of WAVECOM. Not to be distributed or divulged without prior written agreement. Ce document est la propriété exclusive de WAVECOM. Il ne peut être communiqué ou divulgué à des tiers sans son autorisation préalable
4. Select script file to download.
5. Initiate download.
6. Set new script to be active.
7. Set script to run from start. Normally this setting will already be in force in which case this step can be omitted.
8. Reset remote module so that new script will be run.

2.3 Remote GR64 Setup

The GR64 that is to have its script updated by using the RC/IPRC function must have a script with the RC/IPRC functionality active as part of the main loop within the script structure (example Section 3.1.1/3.1.2). The remote GR64 must also have a SIM card with a data number to allow the setup of a CSD call when using RC, or a SIM card which allows for GPRS connections to be made when using IPRC.
The RC embedded application in section 3.1.1 relies upon a data call being received before switching the RC function on. This can also be done in reverse i.e. the embedded application can be made to dial a target server and then switch on the RC function. Likewise, the IPRC embedded application in section 3.1.2 waits for an IP connection to be made, however, the IP connection could also have been initiated from the IPRC script.

2.4 Security aspects

When implementing the code, some thought should be given to ensuring that no unauthorized entity can dial into the module and perform an unauthorized download.
Some methods are described below which are easy to implement and secure in their operation.

2.4.1 SMS Method

The download operation could be triggered by an incoming SMS, the format of which is recognised by the script i.e. the text of the SMS could be
Gx64 APPLICATION NOTE EA Remote Download Page: 7/22
‘Update required: code 1234 call service centre’.
This should be sent from a known number, and could also include a number to dial for RC, or an IP address to connect to for IPRC.
This document is the sole and exclusive property of WAVECOM. Not to be distributed or divulged without prior written agreement. Ce document est la propriété exclusive de WAVECOM. Il ne peut être communiqué ou divulgué à des tiers sans son autorisation préalable

2.4.2 CLIP Method

Alternatively, for RC, the script could be adjusted to activate CLIP (Caller Line Presentation) and only answer the call if it recognised that the call was from its service centre.

2.4.3 IP Address Method

Alternatively, for IPRC, the script could be set up to only accept download connections from specific IP addresses. This would require the download done via a device (PC/Server) with a static IP address.
Gx64 APPLICATION NOTE EA Remote Download Page: 8/22
This document is the sole and exclusive property of WAVECOM. Not to be distributed or divulged without prior written agreement. Ce document est la propriété exclusive de WAVECOM. Il ne peut être communiqué ou divulgué à des tiers sans son autorisation préalable

3 Functional Description of Embedded Application

3.1 Flow Chart of Remote Control Embedded Application

Gx64 APPLICATION NOTE EA Remote Download Page: 9/22
This document is the sole and exclusive property of WAVECOM. Not to be distributed or divulged without prior written agreement. Ce document est la propriété exclusive de WAVECOM. Il ne peut être communiqué ou divulgué à des tiers sans son autorisation préalable

3.1.1 RC Description

This embedded application or something very similar has to be running in the target module to ensure that the download will have a connection to work with.
The first consideration in the script is to establish a data channel. It is possible to establish two instances of a data channel within a script. Either instance can be used. The example script uses channel 1.
Note that if you chose channel 0, atsnd() cannot be used while channel 0 is in data mode.
This example does not feature any security mechanism. It simply uses auto answer on channel 1 and attempts to put any incoming call into RC mode.
This example polls the channel status byte and tests for DCD active to determine if a CSD connection has been made. It continues to poll the status byte for DCD after RC mode is entered to see when the connection drops.
While the module is in RC mode, this script does not execute MyScript (). It assumes that the need for upgrading a script means that the old script should not run.
After the connection drops, the script resets the module, so that the newly downloaded script can run.
Note: It must be noted that the script shown below can only handle ONE call at any given time, be it a voice or data call. If the GR64 is handling a voice call, it CANNOT handle a data call from a user attempting to download a script, until the voice call is cleared (and vice versa).
RemoteMode () { int state;
state = chsts (1) & 0x02;
/* Check to see if the channel is connected */ if (state) { /* Setup Remote Control mode */ if (rc (1) == 1) { prtf ("Entered RC mode, waiting for CSD call to end\r\n"); state = chsts (1) & 0x02;
while (state != 0) { dlys (1); state = chsts (1) & 0x02; }
prtf ("Exited RC mode. Resetting module.\r\n"); rst (0); }
Gx64 APPLICATION NOTE EA Remote Download Page: 10/22
This document is the sole and exclusive property of WAVECOM. Not to be distributed or divulged without prior written agreement. Ce document est la propriété exclusive de WAVECOM. Il ne peut être communiqué ou divulgué à des tiers sans son autorisation préalable
else { prtf ("Failed to enter RC mode\r\n"); } } }
MyScript() { dlys (1); return (0); }
main ()
{ int result;
prs (0);
/* Create data channel to be used for accepting RC call */ chcrt (1);
/* Turn auto answer on for data channel */ chw (1, "ATS0=1\r", 7);
while (1) { result = MyScript (); prtf ("MyScript result: %d\r\n", result); RemoteMode (); } }
Gx64 APPLICATION NOTE EA Remote Download Page: 11/22
This document is the sole and exclusive property of WAVECOM. Not to be distributed or divulged without prior written agreement. Ce document est la propriété exclusive de WAVECOM. Il ne peut être communiqué ou divulgué à des tiers sans son autorisation préalable

3.2 IPRC Embedded Application Code

The following code sample shows how to initiate an IPRC session for RC mode. In this case TCP listen is used so that the module acts as a server and waits for the download application to initiate a TCP/IP connection on port 5001. It is also possible for the module to initiate the connection. Once a connection is established the IPRC function is called to put the module into RC mode enabling remote download to take place.
Note that IPRC will not work with UDP. Also, the script only displays its IP address on the debug port. A proper script would have to include a way of communicating the IP address to the remote end, via SMS, for instance.
int socket;
RemoteMode () { int state; int port; int address;
state = tcpa(socket, &port, &address);
/* Check to see if the socket is connected */ if (state == 0) { /* Setup Remote Control mode */ if (iprc (1, socket) == 1) { prtf ("Entered RC mode, waiting for IP connection to end\r\n"); state = ipstate (socket) & 0x20;
while (state != 0) { dlys (1); state = ipstate(socket) & 0x20; }
prtf ("Exited RC mode. Resetting module\r\n"); rst (0); } else { prtf ("Failed to enter RC mode\r\n"); } } }
MyScript() { dlys (1); return (0); }
Gx64 APPLICATION NOTE EA Remote Download Page: 12/22
This document is the sole and exclusive property of WAVECOM. Not to be distributed or divulged without prior written agreement. Ce document est la propriété exclusive de WAVECOM. Il ne peut être communiqué ou divulgué à des tiers sans son autorisation préalable
main() { int result;
prs (0);
/* Create a pdp context */ result = pdpcont (1, 1, "APN01A.ERICSSON.SE");
if (!result) { /* Activate a PDP context for IP use */ prtf ("PDP context written.\r\n"); result = pdpa (1,1); }
if (!result) { int val;
/* Get this module's IP information */ prtf ("PDP context activated.\r\n"); val = ipi (0); prtf ("My IP address is: %d.%d.%d.%d\r\n", val & 255, (val >> 8) & 255, (val >> 16) & 255, (val >>24) & 255); }
if (!result) { /* Open tcp socket */ prtf ("Opening Socket.\r\n"); result = ipo (1, &socket); prtf ("socket = %d.\r\n", socket); }
if (!result) { int PORTNUM = 5001;
/* Listen on tcp socket */ prtf ("Starting to listen at port number %d\r\n", PORTNUM); result = tcpl (socket, PORTNUM); }
while (1) { result = MyScript (); prtf ("MyScript result: %d\r\n", result); RemoteMode (); } }
Gx64 APPLICATION NOTE EA Remote Download Page: 13/22
This document is the sole and exclusive property of WAVECOM. Not to be distributed or divulged without prior written agreement. Ce document est la propriété exclusive de WAVECOM. Il ne peut être communiqué ou divulgué à des tiers sans son autorisation préalable

Appendix A

Script Download Sequence

Determine active script:
Issue AT*E2APD? which returns *E2APD: <ScriptNum>,<AvlSpace>, where ScriptNum is the slot number of the currently active script so the other slot should be used for the download.
Initiate Xmodem download:
Issue AT*E2APD=0,<slot>,<blocks> where slot is the slot number to script will be downloaded to and blocks is the number of 128 byte blocks required for the script (note this value does not include the header block). The module returns ‘CONNECT<cr><lf>’ to indicated it has entered data mode followed by a single ‘C’ character when it is ready to accept Xmodem blocks.
Download Blocks:
Send each block in turn waiting for an acknowledgment before sending the next block. After receiving each block the module will return one of the following:
ACK character (6) – positive acknowledge, ready for next block.
NAK character (21) – negative acknowledge, previous block should be resent.
CAN character (24) – Cancel, download has failed.
End of Transmission:
Send EOT character (4) – indicates there are no more blocks to send. Module returns ACK, NAK or CAN as above. Once the module has returned ACK to an AOT transmission it will send ‘OK’ to indicate a successful download.
Activate new Script:
Issue AT*E2APD=3,<slot> to activate the new script and wait for ‘OK’ to be returned.
Gx64 APPLICATION NOTE EA Remote Download Page: 14/22
This document is the sole and exclusive property of WAVECOM. Not to be distributed or divulged without prior written agreement. Ce document est la propriété exclusive de WAVECOM. Il ne peut être communiqué ou divulgué à des tiers sans son autorisation préalable
Set Script to run from start:
Issue AT*E2APC=1,1 to set the active script to run from startup.
Restart Module:
If the script running in the module is set to automatically restart then just close the connection. Alternatively, issue AT*E2RESET to restart the module.

Xmodem Block Structure

1 byte SOH character (1)
1 byte block count mod 256
1 byte 255 - block count mod 256
128 bytes block data
2 byte integer (Little Endian) CRC-16/CITT CRC of block data
133 bytes total

Script Header Block

The script to be downloaded should be split into blocks of 128 bytes each. Unused bytes in a block should be padded with 0xFF characters. The first block sent is the script header block with the following structure:
4 byte integer (Little Endian) number of script lines
4 byte integer (Little Endian) number of script constants
4 byte integer (Little Endian) number of script tokens
4 byte integer (Little Endian) number of script keywords
4 byte integer (Little Endian) number of script identifiers
The above script information can be obtained by calling the DLL_SI_GetScriptParameters function available from the slp.dll that accompanies the IDE.
Gx64 APPLICATION NOTE EA Remote Download Page: 15/22
This document is the sole and exclusive property of WAVECOM. Not to be distributed or divulged without prior written agreement. Ce document est la propriété exclusive de WAVECOM. Il ne peut être communiqué ou divulgué à des tiers sans son autorisation préalable

Appendix B

Remote Download Application

This application requires Microsoft .NET Framework 2.0 to be installed on the host PC. Remote download over TCP/IP requires a network connection capable of access the network the remote module is attached to. Note the security features of some corporate firewalls can prevent this. Remote download over CSD requires a serial connection to a GSM modem capable of connecting to the remote module.
Gx64 APPLICATION NOTE EA Remote Download Page: 16/22
Before any operation can be performed the type of connection, TCP/IP or serial, must be selected. The controls for the selected connection type will then become active.
This document is the sole and exclusive property of WAVECOM. Not to be distributed or divulged without prior written agreement. Ce document est la propriété exclusive de WAVECOM. Il ne peut être communiqué ou divulgué à des tiers sans son autorisation préalable

TCP/IP Controls

The application can act as a server by listening for a connection initiated by the remote module or as a client by initiating a connection to a listening remote module.
Connect: This initiates a connection to the remote module which must be in listen mode. The IP address of the remote module must first be entered. If no value is entered for the port number it will default to 5001.
Listen: The IP address of the host PC will be entered automatically but can be changed if required. The port number will default to 5001 if no value is entered. The remote module will require the IP address of the host in order to initiate a connection.
Disconnect: This will close the current connection.

Serial Controls

This mode enables a CSD connection to be established to a remote module using a GSM modem (i.e. another GR64) connected to the host PC’s serial port. It could also be used to download scripts to a locally connected GR64.
COM Port: Select from the available com ports.
Baud Rate: Select either 9600 or 115200 baud.

Common Controls

Once a connection of either type has been established the common communication controls become active.
Send: Sends the text (normally an AT command) entered in the box adding a terminating carriage return. Responses will be displayed in the output box. In serial mode this will be used to send AT commands to the GSM modem on the serial port to establish the CSD connection. Once connection to the remote module is established AT commands can be sent to it.
Gx64 APPLICATION NOTE EA Remote Download Page: 17/22
Script file: Path to the script (.sc) file that will be downloaded. This can be entered in the box or clicking the label will bring up an open file dialog.
This document is the sole and exclusive property of WAVECOM. Not to be distributed or divulged without prior written agreement. Ce document est la propriété exclusive de WAVECOM. Il ne peut être communiqué ou divulgué à des tiers sans son autorisation préalable
Script Slot: Enter the script slot number for download. This must not be the currently active slot. Click the button to automatically get the free slot.
Download: Providing a valid script file and slot number have been entered this will initiate a download. A running block count and any error messages will be displayed in the output box.
Abort: Abort a download or get slot operation that is in progress.
AT Command Buttons: These three buttons provide short cuts to frequently used
script AT commands and are equivalent to entering the commands in the Send box. The commands are as follows:
Set Active: AT*E2AD=3,<slot number>
Run from Start: AT*E2APC=1,1
Run: AT*E2APC=1,0
Gx64 APPLICATION NOTE EA Remote Download Page: 18/22
This document is the sole and exclusive property of WAVECOM. Not to be distributed or divulged without prior written agreement. Ce document est la propriété exclusive de WAVECOM. Il ne peut être communiqué ou divulgué à des tiers sans son autorisation préalable

Appendix C

Remote Download Application via M2mpower IDE

This application is available with M2mpower IDE version 1.1.3 onwards. This needs to be installed on the user PC. Remote download over TCP/IP requires a network connection capable of access the network the remote module is attached to. Note the security features of some corporate firewalls can prevent this. Remote download over CSD requires a serial connection to a GSM modem capable of connecting to the remote module.
1. Using the M2
can be done by either using the “Open Script” icon
m
power IDE, open the script to be downloaded as normal. This
or selecting ‘File’ Menu
- then the ‘Open’ option.
2. Once the script to be downloaded can be viewed in the editing screen, select the remote download form via ‘Download’ Menu – ‘Remote Script Download’ option.
Gx64 APPLICATION NOTE EA Remote Download Page: 19/22
3. The above window will appear allowing the user a choice on how to establish connection, to the remote module. This will be either IP or CSD.
IP – Connect
Enter IP address of remote module in the first box. Enter the port number if not using the default value. Click ‘Connect’
This document is the sole and exclusive property of WAVECOM. Not to be distributed or divulged without prior written agreement. Ce document est la propriété exclusive de WAVECOM. Il ne peut être communiqué ou divulgué à des tiers sans son autorisation préalable
Wait for “TCP/IP Connected” to be displayed (“TCP/IP Connecting” may be displayed initially)
IP – Listen
The IP address of the host PC and the default port number are entered automatically but can be changed manually if required. Click ‘Listen’, “TCP/IP Listening” will be displayed. This will change to “TCP/IP Connected” once the remote module makes contact.
CSD
Enter the phone number of the remote module and click ‘Dial’. Next ‘Dialling CSD’ will be displayed followed by (if all goes well) “CSD Connected”.
4. Once a connection is established by whatever means, select ‘Download’. The ‘Remote Download’ form (below) will appear.
Gx64 APPLICATION NOTE EA Remote Download Page: 20/22
Click ‘Download’ on this form and the script download will proceed as for a normal serial download.
This document is the sole and exclusive property of WAVECOM. Not to be distributed or divulged without prior written agreement. Ce document est la propriété exclusive de WAVECOM. Il ne peut être communiqué ou divulgué à des tiers sans son autorisation préalable
Once the remote download has completed, this form will close automatically. Then select ‘Disconnect’ and wait for “NOT Connected” to be displayed, after which the Remote Download form can be closed.
Note- For Disconnect to work with CSD the default escape sequence (‘+++AT’) must be enabled (AT*E2EST=1). A one second guard time should also be set (AT*E2ESC=1).
Gx64 APPLICATION NOTE EA Remote Download Page: 21/22
This document is the sole and exclusive property of WAVECOM. Not to be distributed or divulged without prior written agreement. Ce document est la propriété exclusive de WAVECOM. Il ne peut être communiqué ou divulgué à des tiers sans son autorisation préalable
Gx64 APPLICATION NOTE EA Remote Download Page: 22/22
This document is the sole and exclusive property of WAVECOM. Not to be distributed or divulged without prior written agreement.
WAVECOM S.A. - 3 esplanade du Foncet - 92 442 Issy-les-Moulineaux Cedex - France - Tel: + 33(0)1 46 29 08 00 - Fax: +33(0)1 46 29 08 08
Ce document est la propriété exclusive de WAVECOM. Il ne peut être communiqué ou divulg à des tiers sans son autorisation préalable
Wavecom, Inc. - 430 Davis Dr. Suite 300 - Res earch Triangle Park, NC 27709 - USA - Tel: +1 9 19 237 4000 - Fax: +1 919 237 4140 WAVECOM Asia Pacific Ltd. - Unit 201-207, 2 Shatin - New Territories, Hong Kong - Tel: +852 2824 0254 - Fax: +852 2824 0255
nd
P
P
Floor - Bio-Informatics Centre - No. 2 Science Park West Avenue - Hong Kong Science Park,
Loading...