Using TCP and UDP Under Open-At

Embed Size (px)

Citation preview

  • 7/21/2019 Using TCP and UDP Under Open-At

    1/13

    P L U G I N T O T H E W I R EL ES S W O R LD

    GIVE W INGS TOYOUR IDEAS

    Using TCP and UDP under Open-AT

    Revision: 001

    Date: June 2003

  • 7/21/2019 Using TCP and UDP Under Open-At

    2/13

    Using TCP and UDP under Open ATTM

    WM_ASW_OAT_APN_017-001

    Author: Wavecom Support Consultant Date: 23thJune 2005

    APN Content Level BASIC INTERMEDIATE ADVANCED Confidentiality Public Private

    Reference Hardware NoSoftware

    Compatibility*Firmware 650a Open AT

    TM V3.01 eDLib V3.0

    CompilerUsed

    ADSGCC Reference Software Yes

    * refer to software compatibility matrix section for more detail

    Modems: M1206B M1306B M2106B

    Quik (CDMA): Q2358C Q2438F Q2438RHardware

    Compatibility Quik (GSM): Q2400A Q2403A Q2406A Q2406B Q2501B

    2004 All rights reserved Page: 1 / 11This document is the sole and exclusive property of WAVECOM. Not to be distributed or divulged without prior written agreement.Ce document est la proprit exclusive de WAVECOM. Il ne peut tre communiqu ou divulgu des tiers sans son autorisation pralable.

    A

    P

    P

    L

    IC

    A

    T

    ION

    NOT

    E

    A

    P

    P

    L

    ICA

    T

    ION

    NOT

    E

    AP

    P

    LIC

    A

    T

    ION

    NOT

    E1 INTRODUCTION

    This document describes the usage of TCP and UDP socketsusing APIs provided by the IP Connectivity library (also namedeDLib) in Open AT

    TM development environment. Applications

    samples given at the end of the document describes the steps tobe followed to open a TCP/UDP connection, manipulate theconnection to send/receive data and close the connection. Some ofremarks which might help during development have also beendescribed in this document.This document assumes that the user has knowledge establishinga session to GPRS/GSM network using eDLib APIs. The user canrefer Open AT

    TMDevelopment Guide for IP connectivity in case

    more information is needed regarding eDLib APIs and returncodes.

    2 APPLICATION DESCRIPTION

    eDLib provides APIs using which Open ATTM

    developers can havedirect access to internet protocols like TCP, UDP, SMTP, FTP andPOP3 with convenient and efficient ways to open and manipulateTCP and UDP sockets. These sockets can either be opened inclient mode (TCP/UDP client) or server mode (TCP/UDP server).eDLib provides various APIs in order to manage these TCP/UDPsockets.

    Important Note: All eDLib APIs are only compatible with ADLmode of application development and should not be used withstandard mode of application development. It is recommended to

    use eDLib in Open AT

    TM

    application written in ADL mode.

    2.1 Synopsis of Various Operations performed.

    There are several operations which have to be performed for asuccessful TCP/UDP socket connection. These operations arebriefly described as under. Please note that the first six steps (i vi) are common for both client and server sockets (TCP/UDP).

    i. Call ed_Init () API from adl_main (program entry point).

    ii. Wait for +WIND: 4 indication.

    iii. Perform GPRS attach operation. This can be done byissuing AT+CGATT=1 command usingadl_atCmdCreate () API. Please note that this step is notrequired if the GSM data call is used to make TCP/UDPconnection. In case, GPRS services are used to make

    TCP/UDP connection, only then GPRS attach should beperformed.

    iv. Set the GPRS parameters using ed_GprsSetConfig ()API. These parameters include the Access Point Name(APN) string, APN username, APN password.ed_GprsSetConfig () API is also used to set a modeparameter. This parameter indicates to eDLib whetherGSM data call or GPRS connection should be used forthe TCP/UDP socket. Hence, ed_GprsSetConfig () APIhas to be called irrespective of the fact whether GSMdata call or GPRS connection is used for TCP/UDPsocket.

    v. If GSM data call is used to establish a connection, thenGSM call parameters have to be set too. This is doneusing DialupSetConfig () API. Please note this step

    should be performed only when GSM data call is usedfor TCP/UDP sockets. This step is not required if GPRSconnection is used for TCP/UDP sockets.

    vi. Call ed_DialupConnectionStart () API. Depending uponthe mode parameter (which is set usinged_GprsSetConfig () API), GSM data call or GPRSconnection will be made. If the connection is successful,an IP address will be received by the module.

    vii. If TCP socket has to be established, then set the TCPclient/server parameters using ed_SocketSetConfig ()

    API. If UDP socket has to be established, then setup theUDP client/server parameters usinged_UdpSocketSetConfig () API.

    viii. To use TCP client/server socket, called_SocketTCPStart () API. To start a UDP client/serversocket, call ed_SocketUDPStart () API.

    ix. The Response Handler function for TCP/UDP sockets(specified in the ed_SocketTCPStart () ored_SocketUDPStart ()) will indicate various eventsrelated to socket services (like successful socketconnection, or failure to connect to server TCP)).

    x. The data handler function for TCP/UDP sockets(specified in the ed_SocketTCPStart () ored_SocketUDPStart ()) will be invoked whenever data isreceived from the peer TCP/UDP socket.

    xi. The data request handler function for TCP/UDP socket(specified in the ed_SocketTCPStart () ored_SocketUDPStart ()) will be invoked to indicate thatthe socket can now send data. The MaxLen parameterof data request handler will indicate the maximum length

    of data can be sent at this time.

    xii. In case of TCP sockets, data should be sent (to the peerTCP socket) using ed_SendDataExt () API. In case ofUDP sockets, data should be sent (to the peer UDPsocket) using ed_SendData () API. These APIs(ed_SendDataExt () and ed_SendData () should be usedto close active TCP and UDP client/server sockets). Itshould be noted that a listening TCP server socketshould be closed with ed_SocketLTCPStop () API and alistening UDP server socket should be closed withed_SocketLUDPStop () API.

    The sections below describe the details of various operationsrequired for successful TCP/UDP connection establishment alongwith the precautions which must be taken for proper operation.

    2.2 Preliminary Tasks before Opening a TCP/UDPsocket.

    Before Opening a TCP/UDP socket, some tasks like attaching toGPRS network or connecting to GSM service provider (in casedialup connection is used) must be performed. These basic tasksallow the module to use the services offered by the network to useTCP/UDP sockets. eDLib provide full set of APIs to allowapplication to do these preliminary tasks.The following section describes most used APIs to perform thesetasks.

    2.2.1 Starting up eDLib

    Before using any APIs, eDLib must initialise its own data structures

    and run some initialisation routines (like subscribing to differentflows internally to send and receive data, loading IP connectivityparameters from EEPROM etc). This is done using ed_Init

  • 7/21/2019 Using TCP and UDP Under Open-At

    3/13

    Using TCP and UDP under Open ATTM

    WM_ASW_OAT_APN_017-001

    2004 All rights reserved Page: 2 / 11This document is the sole and exclusive property of WAVECOM. Not to be distributed or divulged without prior written agreement.Ce document est la proprit exclusive de WAVECOM. Il ne peut tre communiqu ou divulgu des tiers sans son autorisation pralable.

    A

    P

    P

    L

    IC

    A

    T

    ION

    NOT

    E

    A

    P

    P

    L

    ICA

    T

    ION

    NOT

    E

    AP

    P

    LIC

    A

    T

    ION

    NOT

    E

    function. This API must be called before calling any other eDLibAPI. This API has the following prototype:s8 ed_Init (void);Parameters: None.Return Values:

    0is returned on Success.

    ED_ERR_NO_TCPIPis returned if TCP/IP feature is not

    activated in the WISMO product.

    ED_ERR_TCPIP_ALREADY_USED is returned ifanother application is already using IP connectivitylibrary.

    ED_ERR_WM_UNABLE_SUBS_EVENT is returned ifeDLib failed to internally subscribe for commands, timersor unsolicited messages.

    ED_ERR_PARAM_READ_E2P is returned if Parameterreading from E2P failed.

    Remarks: ed_Init () must be called from adl_main () for proper

    operation.

    In case, the application wants to initialise PIN code using

    adl_simSubscribe () API, ed_Init must be called aftercalling adl_simSubscribe () API.

    2.2.2 +WIND: 4 Indication and Configuration Modes

    TCP/UDP sockets use the data services provided by the networkprovider to exchange data and hence, establishing a connection tonetwork service provider is important. Whenever SIM is insertedinto the module, connection tried to be established with the serviceprovider and it takes some time to initialise the SIM and register tothe network. +WIND: 4 indication should be used to indicatecomplete network registration confirmation. Application cansubscribe for +WIND: 4 indication (using adl_atUnSoSubscribe ()

    API) to confirm complete network registration and then initiate therelated TCP/UDP client/server operations.

    After receiving a +WIND: 4 indication, the application can start

    TCP/UDP socket using either GSM data call or GPRS connection.Initial settings need to be setup for GSM data call and/or GPRSconnection prior to starting TCP/UDP connection. The GSM datacall and GPRS connection which are used to transport TCP/UDPdata are called mode for TCP/UDP sockets. The application caneither use GSM data call mode or GPRS connection mode forTCP/UDP services.

    2.2.3 How does Modem know which mode to use?

    It is very important to provide the information regarding the mode(GSM data call or GPRS connection) used for TCP/UDP socketconnection. This information can be provided usinged_GprsSetConfig (). This API is used to provide GPRS settingsrelated information and the mode to be used for TCP/UDPconnection to the module.ed_GprsSetConfig () API requires an instance of

    ed_gprsSetupParams_t structure as its argument. The members ofed_gprsSetupParams_t structure include:

    Cid: This parameter represents the context id which hasto be activated if a GPRS connection is made.

    Mode: This parameter indicates whether GSM data callor GPRS connection is used to provide data transportservices for TCP/UDP sockets. The values which thisparameter can take along with their meanings are:

    Mode Meaning

    0 If this parameter is set to 0, itindicates that GSM data callshould be used for providing datatransport facility to the TCP/UDPclient/server. In this case, theapplication should also set thedialup parameters usinged_DialupSetConfig () API.

    1 If mode is set to 1, then GPRSconnection is used to provide datatransport facility to TCP/UDPclient/server. In this case, onlyGPRS parameters becomesignificant and there is no need toset the dialup parameters.

    ApnServ: This parameter represents the APN servername.

    ApnUn: This parameter represents the APN user name.

    ApnPw: This parameter represents the APN password.

    Note that APN is the acronym for Access Point Name.

    2.2.4 Using GPRS Service for TCP/UDP sockets

    If the application is using GPRS connection for TCP/UDP sockets,it should first attach to the GPRS network. This can be done byusing AT+CGATT=1 command. This command can be issued tothe core software using adl_atCmdCreate () API. After the GPRSnetwork is successfully attached, various GPRS parameters shouldbe set. These parameters include the ApnServ, ApnUn, ApnPw,Cid and Mode.These parameters are available as members ofed_gprsSetupParams_t structure. For GPRS connection, theMode parameter should be set to 1. ApnServ, ApnUn and ApnPwparameters are dependent of the network service provider.ed_gprsSetConfig () API can be used to configure the GPRSparameters for use in the TCP/UDP socket. This API requires an

    instance of ed_gprsSetupParams_t structure (which contains theGPRS parameters like ApnServ, ApnUn and ApnPw).Now ed_DialupConnectionStart () API can be called to establish anIP connection and receive an IP address.

    2.2.5 Using GSM Data Call for TCP/UDP sockets.

    If the application wants to use GSM data call for TCP/UDP socketthen it should be indicated by setting Mode parameter ofed_gprsSetupParams_t structure to 0. This parameter should beset using ed_GprsSetConfig () API. However, there is no need toset other parameters of ed_gprsSetupParams_t (excluding mode)as they will not be used here.

    After setting mode parameter using ed_GprsSetConfig () API,GSM dialup parameters should be set. These parameters aremembers of ed_dialupSetupParams_t structure as follows :

    DialN1: This is the primary dialup phone number toconnect with the local ISP. This is a string typeparameter and can have a maximum length of 64(excluding the terminating NULL character).

    DialN2: This is the secondary dialup phone number toconnect with the local ISP. Its data type and maximumlength is same as the DialN1 parameter.

    DialSelect: This parameter determine whether primarydialup phone number (DialN1) or secondary dialupphone number (DialN2) is used to establish aconnection.

    IspUn: This is the user name of the ISP account in ASCIItext string and can be up to 64 characters in length. Bydefault, it is set to empty string.

  • 7/21/2019 Using TCP and UDP Under Open-At

    4/13

    Using TCP and UDP under Open ATTM

    WM_ASW_OAT_APN_017-001

    2004 All rights reserved Page: 3 / 11This document is the sole and exclusive property of WAVECOM. Not to be distributed or divulged without prior written agreement.Ce document est la proprit exclusive de WAVECOM. Il ne peut tre communiqu ou divulgu des tiers sans son autorisation pralable.

    A

    P

    P

    L

    IC

    A

    T

    ION

    NOT

    E

    A

    P

    P

    L

    ICA

    T

    ION

    NOT

    E

    AP

    P

    LIC

    A

    T

    ION

    NOT

    E

    IspPw: This is the password for the ISP account in ASCIItext string and can be up to 64 characters in length. Bydefault, it is also set to empty string.

    RedialCount: This parameter indicates how manyunsuccessful connections (between 0 and 14 inclusive)attempts will be tried by the TCP/IP stack softwarebefore terminating the connection attempts. If the value

    is set to 0, the TCP/IP stack software will not make anycall retry. This parameter is by default set to 5.

    RedialDelay: This parameter controls elapsed idle time(in seconds between 5 and 14 inclusive), if any, it willtake between each call retry.

    PhyTimeout: This parameter is used by TCP/IP stacksoftware in order to terminate connections to telephoneline without activity. This period represents time inminutes between 1 and 255 and by default it is set to 15.

    Then ed_DialupSetConfig () API can be used to set theseparameters for GSM data connection. This API expects aninstance of ed_dialupSetupParams_t as its argument.

    Now ed_DialupConnectionStart () API can be used to establish an

    IP connection and receive an IP address from the network.The whole procedure (starting from +WIND: 4 wait toed_DialupConnectionStart () is briefly described as under):

    1. Attach to GPRS using AT+CGATT=1 command. (Thisoperation can be done even before receiving +WIND :4indication). However, if GSM is used to connect to theservice provider, there is no need to perform this step.

    2. Set up GPRS parameters (like ApnServ, ApnUn, mode,cid, etc) using ed_GprsSetConfig () API. The modeparameter should be set to 0 if GSM data call is used toprovide data transport to the TCP/UDP sockets. IfGPRS is used to provide data transport to the TCP/UDPsocket, the mode parameter should be set to 1. ForGSM data connection, GSM parameters (DialSelect,DialN1 etc) should also be set usinged_DialupSetConfig () API.

    3. Starting the connection using ed_DialupConnectionStart() API. ed_DialupConnectionStart () function willestablish the connection depending on the modeparameter of ed_gprsSetupParams_t.

    Remarks: Even if the application is using GPRS to provide eDLib

    services, it should wait for +WIND: 4 indication beforecalling ed_DialupConnectionStart () API. In case, this isnot done, ED_ERR_WM_GPRS_OPEN (error code -28)is received by the response callback function ofed_DialupConnectionStart () API (ed_ResponseCbk_f).

    When GPRS is used to connect to ISP,ed_DialupConnectionStart () function should not be

    called immediately after receiving response forAT+CGATT command (i.e. connecting to GPRS). Somedelay should be provided (using a timer) between callinged_DialupConnectionStart () and receiving OKresponse in the command handler of AT+CGATT=1 command (AT+CGATT=1 command can be sent to thecore software using adl_atCmdCreate () API).

    When GSM is used to connect to ISP and provide eDLibservices, there is no need to connect to GPRS using

    AT+CGATT=1. In this case, the application should simplywait for +WIND: 4 indication, setup the dialup parameters(using ed_DialupSetConfig () API) and GPRSparameters (to set mode parameter usinged_GprsSetConfig () API) and called_DialupConnectionStart () API.

    2.3 TCP Sockets

    Required header file: ed_socket.heDLib provides TCP services which allow an application to openTCP client or TCP server sockets. When a TCP socket is openedin a server mode, it listens on the specified port for any connectionrequest from a client. In case a connection request is received,data can be exchanged between the client and the TCP server.

    2.3.1 Setting up TCP Socket Parameters

    Before starting TCP connection, parameters for the TCP socketshould be set. These parameters are members ofed_SocketSetupParams_t structure.Members of ed_SocketSetupParams_tstructure include:

    TcpPort: This parameter holds the peer TCP port if aclient TCP socket is opened.

    ORIf a server TCP socket is opened, then this parameterindicates the port on which the TCP server will listen forincoming connections.Default Value: 0Type: u16Range: 1 to 65535.

    TcpTxDelay: This parameter holds delay after which thesocket will flush the characters to transmit to the remoteentity. EDLib usually buffers the characters until itstransmit buffer is full or the TcpTxDelay time expires.Default Value: 100msType: u16

    TcpServ:If a client TCP socket is opened: This parameter will

    hold the TCP server IP address to connect to.OR

    If a server TCP socket is opened: Thisparameter indicates the IP filtering which has to be done.

    A value of 255.255.255.255 indicates no IP filtering. Default Value: Empty string ().

    Type: Array of ascii data type.

    Remarks: A value of 0.0.0.0 for TcpServ parameter in inval id

    for both client and server TCP socket.

    A TCP client socket cannot specify a value of255.255.255.255 as TcpServ parameter. (This isbecause, no server can have 255.255.255.255 asits IP address). However, this value should bespecified for a TCP server socket if no IP filtering isperformed.

    After setting values in the members of ed_SocketSetupParams_tstructure, ed_SocketSetConfigAPI should be used to set thesevalues for the TCP socket.

    This API has the following prototype:s8 ed_SocketSetConfig (TeDHandle id,

    ed_SocketSetupParams_t * Params);

    Parameters:

    id: This parameter specifies the socket id for which theparameters are to be set. It can have one of the followingvalues:

    ED_ID_TCPSOCKET_1

    ED_ID_TCPSOCKET_2

    ED_ID_TCPSOCKET_3

    ED_ID_TCPSOCKET_4

    ED_ID_TCPSOCKET_5

    ED_ID_TCPSOCKET_6

    ED_ID_TCPSOCKET_7

  • 7/21/2019 Using TCP and UDP Under Open-At

    5/13

    Using TCP and UDP under Open ATTM

    WM_ASW_OAT_APN_017-001

    2004 All rights reserved Page: 4 / 11This document is the sole and exclusive property of WAVECOM. Not to be distributed or divulged without prior written agreement.Ce document est la proprit exclusive de WAVECOM. Il ne peut tre communiqu ou divulgu des tiers sans son autorisation pralable.

    A

    P

    P

    L

    IC

    A

    T

    ION

    NOT

    E

    A

    P

    P

    L

    ICA

    T

    ION

    NOT

    E

    AP

    P

    LIC

    A

    T

    ION

    NOT

    E

    ED_ID_TCPSOCKET_8

    ED_ID_TCPSOCKET_9

    ED_ID_TCPSOCKET_10

    Params: Structure containing the parameters to setup (oftype ed_SocketSetupParams_t).

    Return Values: 0is returned on success.

    ED_ERR_NO_TCPIPis returned if TCP/IP feature is notactivated in the WISMO product.

    ED_ERR_NOT_INIT is returned if the function cannot beused as ed_Init () API is not called prior to callinged_SocketSetConfig API.

    ED_ERR_INVALID_ARG is returned if an argument isinvalid or contains a NULL pointer.

    ED_ERR_PARAM_BAD_VALUE is returned if aparameter value is invalid.

    ED_ERR_PARAM_TOO_LONG is returned if aparameter string is too long.

    ED_ERR_PARAM_WRITE_E2P is returned if writing aparameter to E2P failed.

    ED_ERR_INVALID_IDis returned if the parameter id isinvalid.

    ED_ERR_SERVICE_ALREADY_RUNNING is returnedif the associated TCP service is already running and it isnot possible to set the parameters.

    Important Note:The parameter TeDHandle id is provided only inIP library for Open AT

    TM version 3.xx. It is not available in Open

    ATTM

    version 2.xx. The eDLib APIs for Open ATTM

    version 3.xx andversion 2.xx differs because of this additional parameter only.

    2.3.2 Starting up TCP Client/Server Socket.

    After setting parameters for the TCP socket, a client or a serverTCP socket can be opened. A client TCP socket will try to establisha TCP connection with the TCP server specified in theTcpServparameter of ed_SocketSetupParams_t structure. Aserver TCP socket, on the other hand, will passively listen for anyTCP connection destined for it. It must be noted that in case of aserver TCP socket, connection will become active only after clientconnect to it on the correct port. Otherwise, the server socket willlisten for any incoming connection requests on the specified port.In order to open a client or a server TCP connection the following

    API should be used.s8 ed_SocketTCPStart (TeDHandle id, u8 Listen,

    ed_ResponseCbk_f pfResponseCbk,ed_DataHandler_f pfDataHnd,ed_DataRequest_f pfDataRequest);

    Parameters:

    id: This parameter specifies the socket id. It can haveone of the following values:

    o ED_ID_TCPSOCKET_1

    o ED_ID_TCPSOCKET_2

    o ED_ID_TCPSOCKET_3

    o ED_ID_TCPSOCKET_4

    o ED_ID_TCPSOCKET_5

    o ED_ID_TCPSOCKET_6

    o ED_ID_TCPSOCKET_7

    o ED_ID_TCPSOCKET_8

    o ED_ID_TCPSOCKET_9

    o ED_ID_TCPSOCKET_10

    Listen: This parameter determines whether a client or aserver TCP socket is to be opened with parameter set to1 for TCP socket server and 0 for TCP socket client. Asa server TCP socket listens for any incomingconnections whereas a client TCP socket attempts toconnect to the server TCP socket.

    pfResponseCbk: This parameter is the callback function

    which is called on any event related to TCP connection.All the events related to TCP sockets (like successfulopening of TCP socket, closing of TCP socket,occurrence of some error) lead to execution of thisfunction. This callback function has the followingprototype :

    typedef void (*ed_ResponseCbk_f) (s32ResponseCode, TeDHandle id) ;

    Parameters:

    ResponseCode :

    This parameter will contain the actual TCP socket eventwhich has occurred. This parameter can have thefollowing values (and consequently following TCP socketevents):

    ED_INFO_LISTEN_SET: This event indicates thatthe listening TCP socket has been successfullycreated and now it is waiting for any remote entity(TCP client) to connect to it. This event is relevantonly for a TCP server socket.

    ED_OK_TCP_CLOSED: This event indicates theTCP server/client socket has been successfullyclosed.

    ED_INFO_WAITING_FOR_DATA: This eventindicates that IP library is waiting for data to be sentto it. This event occurs when a TCP client socketsuccessfully establishes a TCP connection with theTCP server socket. If this event occurs on a TCPserver socket, it indicates that some client sockethas successfully made connection with it and theconnection is now active. It indicates that data cannow be send to the TCP server socket from theclient socket or vice versa.

    ED_ERR_DISTANT_DNS:This error indicates thatthe Remote server name has not been mapped byDNS. TCP/IP stack is not able to reach the primaryand secondary DNS servers or a wrong serveraddress has been filled in.

    ED_ERR_DISTANT_OPEN: This error indicatesthat some error has occurred during IP connectivitylibrary application session opening.

    ED_ERR_STACK_INTERNAL:This error indicatessome internal IP stack error.

    ED_ERR_LISTEN_STOP:This event indicates thatthe listening TCP socket has been cancelled. Thisevent is received when ed_SocketLTCPStopfunction is used to stop the listening TCP serversocket.

    ED_ERR_DISTANT_NO_RESP: In case, a clientTCP socket is opened, this event indicates that thedistant TCP server did not responded despite ofrepeated attempts.

    ED_ERR_DISTANT_SEND: This event indicatesthat the data sending attempt from the TCP socketfailed.

    ED_ERR_DISTANT_CLOSE: This event indicateserror during IP library application closing.

    ED_ERR_DISTANT_TCP_CLOSED: This eventindicates that the TCP session is closed by the IPconnectivity library (eDLib).

  • 7/21/2019 Using TCP and UDP Under Open-At

    6/13

    Using TCP and UDP under Open ATTM

    WM_ASW_OAT_APN_017-001

    2004 All rights reserved Page: 5 / 11This document is the sole and exclusive property of WAVECOM. Not to be distributed or divulged without prior written agreement.Ce document est la proprit exclusive de WAVECOM. Il ne peut tre communiqu ou divulgu des tiers sans son autorisation pralable.

    A

    P

    P

    L

    IC

    A

    T

    ION

    NOT

    E

    A

    P

    P

    L

    ICA

    T

    ION

    NOT

    E

    AP

    P

    LIC

    A

    T

    ION

    NOT

    E

    ED_ERR_DISTANT_TCP_CLOSED_BY_PEER:This event indicates that the TCP session is closedby the remote TCP peer.

    ED_ERR_NETWORK_KO: This event indicatesthat the WISMO module is not connected to thenetwork when an attempt was made to open a TCPsocket.

    ED_ERR_GPRS_SESSION_LOST: This eventindicates that the GPRS session has lost activation.This event occurs when GPRS connection is lostwith a TCP socket opened in client or server mode.

    Remarks:

    ED_ERR_LISTEN_STOPevent is received when alistening TCP socket is closed usinged_SocketLTCPStop API. Once the listening serversocket has made a connection with a client TCPsocket, it becomes active and ed_SocketLTCPStop

    API cannot be used to close this socket. Onlylistening TCP server sockets can be closed withed_SocketLTCPStop API. When a listening socketis closed, first ED_OK_TCP_CLOSEDevent will be

    received and after that ED_ERR_LISTEN_STOPevent will be received.

    In case GSM network is used to establishconnection with service provider (instead of GPRS),then due care should be given to the PhysicalTimeout parameter (PhyTimeout) ofed_dialupSetupParams_t structure. This isbecause, if the period of inactivity reaches up to thetime specified in the PhyTimeout parameter, theGSM data call will be released (Physical connectionwill be released) and the TCP client/server socketwill be closed. In this caseED_ERR_NETWORK_KOevent will be received inthe TCP Event Handler function.

    In case GPRS is used to establish connection with

    service provider, there is no Physical Timeoutvalue.

    pfDataHnd: This function is called by eDLib wheneverdata is received by the library from peer entity. Thiscallback function has the following prototype :

    typedef u16 (*ed_DataHandler_f) (u16 DataLen, u8*Data, TeDHandle id);

    Parameters: DataLen: This parameter indicates the number of

    bytes (u8) received by the IP library.

    Data: This is a pointer to the actual data receivedby eDLib.

    id: Specifies the socket id. Please refer section(2.3.2)for the values which can be assigned to thisparameter.

    Return Value: The return value of this callback functionindicates the number of bytes (u8) which are processedby the application. The application should return thenumber of bytes which has successfully processed. Thedata left will be handed over at the next call to thisfunction, maybe with new data.

    pfDataRequest: This is the callback function which iscalled by IP library (eDLib) to inform the application newdata can be sent. Whenever a TCP client socket isopened, this function is called. Inside this function, datacan be sent to the TCP server socket. This function hasthe following prototype :

    typedef void (* ed_DataRequest_f) (u16 MaxLen,TeDHandle id) ;

    Parameters:

    MaxLen: This parameter indicates the maximumnumber of bytes which can be sent by theapplication during this call to the function.

    id: This parameter specifies the socket id. Pleaserefer section (2.3.2) for the values which can be

    assigned to this parameter.Return Value (of pfDataRequest callback function):None.

    Remarks: ed_DataRequest_f callback function is

    automatically called when a client TCP socketestablishes a connection with a server TCP socket.In other words, in case of client TCP socket, thiscallback function is called immediately afterreceiving ED_INFO_WAITING_FOR_DATA eventin the pfResponseCbk function.

    In case of TCP server socket, this function(ed_DataRequest_f) is called when a client getsconnected to it.

    Data send operation (using ed_SendDataExt ()API) should be preferable performed in this functionbecause, if data is sent without receiving a call topfDataRequest API, error code -51(ED_ERR_INVALID_CALL) will occur.

    Return Values (of ed_SocketTCPStart () API):

    0is returned on success.

    ED_ERR_NO_TCPIP is returned if TCP/IP featureis not enabled on the product.

    ED_ERR_NOT_INITis returned if ed_Init () has notalready been called.

    ED_ERR_INVALID_ARG is returned if an

    argument is invalid or NULL.

    ED_ERR_STACK_BAD_CONFIG is returned if IPconnectivity library has incorrect configuration.

    ED_ERR_PHY_NOT_ACTIVATEDis returned if IPconnectivity library physical connection is notactivated. This event occurs when physicalconnection (GPRS connection or GSM call) is notactive at the time of data transfer.

    ED_ERR_STACK_BUSY is returned if another IPconnectivity library application is already running.

    ED_ERR_INVALID_ID is returned if the idparameter is invalid.

    ED_ERR_MEMALLOC_FAILEDis returned if thereis not enough memory left to run the new socket.

    ED_ERR_SOCKET_CREATION_BUSYis returnedif an attempt is made to open more than twosockets at the same time.

    2.3.3 Sending Data and/or Closing TCP client/server socket.

    To send data and/or close the opened TCP client/server socket,ed_SendDataExt API should be used. This API is made explicitlyfor TCP socket services. This API should preferably be called frompfDataRequest callback function (This API can also be calledoutside pfDataRequest API, but there must be a call topfDataRequest function before this API call).

    s8 ed_SendDataExt (u8 * Data, u16 DataLen, bool bEnd,

    TeDHandle id) ;Parameters:

  • 7/21/2019 Using TCP and UDP Under Open-At

    7/13

    Using TCP and UDP under Open ATTM

    WM_ASW_OAT_APN_017-001

    2004 All rights reserved Page: 6 / 11This document is the sole and exclusive property of WAVECOM. Not to be distributed or divulged without prior written agreement.Ce document est la proprit exclusive de WAVECOM. Il ne peut tre communiqu ou divulgu des tiers sans son autorisation pralable.

    A

    P

    P

    L

    IC

    A

    T

    ION

    NOT

    E

    A

    P

    P

    L

    ICA

    T

    ION

    NOT

    E

    AP

    P

    LIC

    A

    T

    ION

    NOT

    E

    Data:This parameter is the pointer to the data which hasto be sent to the peer TCP entity.

    DataLen: This parameter is the length of data which is tobe sent to the peer TCP entity.

    bEnd: This Boolean parameter specifies whether theblock of data to be sent is the last one or not.

    bEnd = TRUE indicates that the current block is the lastblock of data to be sent and the TCP socket will beclosed after sending this block.This is the ideal way toclose any TCP client or server socket.bEnd = FALSE indicates that the current block beingsent is not the last block of data. In this case, eDLibwill call pfDataRequest () API again.

    id: This parameter specifies the socket id which issending the data. Please refer section (2.3.2) for thevalues which can be assigned to this parameter.

    Return Values:

    A 0is returned on success.

    ED_ERR_NO_TCPIPis returned if TCP/IP service is notsupported by the product.

    ED_ERR_NOT_INIT is returned if ed_Init () API has notbeen called yet.

    ED_ERR_INVALID_ARG is returned if Data parameterpoints to NULL value.

    ED_ERR_INVALID_CALL is returned if the API cannotbe invoked now. This might happen if application callsthis API without receiving ed_DataRequest_f () function.This error can also arise if no eDLib service iscurrently active.

    ED_ERR_INVALID_SIZE is returned if DataLenparameter is greater than expected.

    ED_ERR_INVALID_IDis returned if the id parameter isinvalid.

    ED_ERR_ID_INACTIVE is returned if the servicerepresented by the id is inactive.

    Remarks:

    ed_SendDataExt () API should preferably be calledinside ed_DataRequest_f () callback function.ed_SendDataExt () API must not be called beforereceiving call to ed_DataRequest_f () function.

    When ed_SendDataExt () function is called, the MaxLenparameter of ed_DataRequest_f () function must betaken into account. (This parameter indicates themaximum size of block in bytes which can be sent now).

    The data block sent using ed_SendDataExt () functionmust have a size less than or equal to the MaxLenparameter of ed_DataRequest_f () callback.

    The bEnd parameter should be set to TRUE to send thelast block of data and to close the TCP client/ serversocket. If it is set to FALSE, then eDLib will callpfDataRequest () API again.

    ed_SendData () API can also be used to send data. But itcan be used to send data and close connection for TCPserver socket only. As ed_SendDataExt () is madeexplicitly for TCP sockets, it is recommended to useed_SendDataExt () to send data and close the socket forboth TCP client and TCP server sockets.

    2.3.4 To close a listening TCP Server socket.

    A listening socket is listening for some incoming connection andhas not received any connection request yet. In order to close alistening TCP server socket the following API should be used:

    s8 ed_SocketLTCPStop (TeDHandle id, ed_ResponseCbk_fpfResponseCbk);

    Parameters:

    id: This parameter specifies the socket id which is sendingthe data. Please refer section (2.3.2)for the values whichcan be assigned to this parameter.

    pfResponseCbk: This is the callback function which is

    called by IP library to indicate various socket relatedevents (like socket close, or some error condition). Formore information on this callback, please refer section2.3.2

    Return Values:

    0 is returned on success.

    ED_ERR_NO_TCPIPis returned if TCP/IP feature is notenabled on the product.

    ED_ERR_NOT_INIT is returned if ed_Init () API is notcalled prior to calling ed_SocketLTCPStop() API.

    ED_ERR_INVALID_ARG is returned if one of thearguments is invalid or has NULL value.

    ED_ERR_NO_LISTEN is returned ifed_SocketLTCPStop () is called when no socket isopened in listening mode.

    ED_ERR_INVALID_ID is returned if the socket id is notcorrect.

    Remarks: Once a listening socket makes a connection with a

    client, it becomes active and cannot be closed byed_SocketLTCPStop () API. To stop the activesocket, use ed_SendDataExt ()(section2.3.3).

    2.4 UDP Sockets

    Required Header file: ed_udpsocket.heDLib provides UDP socket services, which like TCP socketservices, allow an application to send and receive UDP packets(called UDP datagrams). The difference between TCP and UDP isthat, UDP is a connectionless protocol whereas TCP is connectionoriented protocol. TCP provides reliable delivery of packetswhereas UDP does not. In UDP, a packet (datagram) can betransmitted without establishing a connection with the peer (i.e. aclient can send a datagram without establishing a connection withUDP server).

    2.4.1 Setting up UDP socket parameters.

    Before starting up a UDP client/server socket, some parametershave to be set, which determine the operation of UDP sockets.These parameters are in the ed_UdpSocketSetupParams_tstructure. Members of this structure include:

    UdpPort:

    If a UDP client socket is opened:- This parameter holds thepeer UDP port used (Server UDP port)

    ORIf a UDP server socket is opened:-This parameter indicatesthe port on which the UDP server will listen for incomingconnections.Default Value: 0Type: u16Range: 1 to 65535.

    UdpTxDelay:

    This parameter holds the delay after which after which thesocket will flush the characters to transmit to the remoteentity. eDLib usually buffers the characters until its transmitbuffer is full or the UdpTxDelay time expires.Default Value: 100ms

    Type: u16 UdpServ : This parameter will hold the UDP server IP

    address if a client UDP socket is opened. In case, a

  • 7/21/2019 Using TCP and UDP Under Open-At

    8/13

    Using TCP and UDP under Open ATTM

    WM_ASW_OAT_APN_017-001

    2004 All rights reserved Page: 7 / 11This document is the sole and exclusive property of WAVECOM. Not to be distributed or divulged without prior written agreement.Ce document est la proprit exclusive de WAVECOM. Il ne peut tre communiqu ou divulgu des tiers sans son autorisation pralable.

    A

    P

    P

    L

    IC

    A

    T

    ION

    NOT

    E

    A

    P

    P

    L

    ICA

    T

    ION

    NOT

    E

    AP

    P

    LIC

    A

    T

    ION

    NOT

    E

    server UDP socket is opened, this parameter indicatesthe IP filtering which has to be done. (A value of255.255.255.255 indicates no IP filtering).

    Default Value: Empty string ().Type: array of ASCII data type.Length: 121 (including the NULL terminating string).

    Remarks: A value of 0.0.0.0 for UdpServ parameter in invalid for

    both client and server UDP socket.

    A UDP client socket cannot specify a value of255.255.255.255 as UdpServ parameter. (This isbecause, no server can have 255.255.255.255 as its IPaddress). However, if a UDP server specifies this valuefor UdpServ Parameter, it indicates that no IP filteringshould be performed.

    After setting the values of above parameters in an instance ofed_UdpSocketSetupParams_t structure, these parametersshould be set for the UDP socket to be started. The following APIis used to set the parameters for the socket:s8 ed_UdpSocketSetConfig (ed_UdpSocketSetupParams_t

    *Params);

    Parameters: Params: Structure containing the values to setup. This

    structure must be filled by the application prior to callingthis API.

    Return Values:

    0is returned on Success.

    ED_ERR_NO_TCPIPis returned if TCP/IP feature is notactivated in the WISMO product.

    ED_ERR_NOT_INITis returned if the function cannot beused as ed_Init () API is not called prior to callinged_SocketSetConfig API.

    ED_ERR_PARAM_BAD_VALUE is returned if aparameter value is invalid.

    ED_ERR_PARAM_TOO_LONG is returned if aparameter string is too long.

    ED_ERR_PARAM_WRITE_E2P is returned if writing aparameter to E2P failed.

    ED_ERR_INVALID_ARG is returned if an argument isinvalid or contains a NULL pointer.

    ED_ERR_SERVICE_ALREADY_RUNNING is returnedif the associated UDP service is already running and it isnot possible to set the parameters.

    2.4.2 Starting up UDP client/server socket

    eDLib provides API which can be used to start UDP Client/Serversocket. The parameters for socket must be configured before

    starting the socket using ed_UdpSocketSetConfig ()API. A clientsocket, after successful opening can immediately send data to thespecified server on the specified port. There is no need to make aconnection like TCP socket services. The UDP server socket, likeits TCP counterpart, will passively listen for any connectionsdestined for it. To open a UDP client/server socket, the following

    API should be used:

    s8 ed_SocketUDPStart (u8 Listen, ed_ResponseCbk_fpfResponseCbk, ed_DataHandler_f pfDataHnd,ed_DataRequest_f PfDataRequest);

    Parameters:

    Listen: This parameter determines whether a client or aserver UDP socket is opened. If a server UDP socket isopened, then this parameter is set to 1. On the other

    hand, If a client UDP socket is opened, then thisparameter is set to 0 because, only server UDP socketslistens on a specified port, where client UDP socket will

    attempt to exchange data with the server on the listeningport.

    pfResponseCbk: This parameter is a callback functionwhich is automatically called by the eDLib whenever anyevent related to UDP socket service occurs. Thisfunction has the following prototype :

    typedef void (*ed_ResponseCbk_f) (s32ResponseCode, TeDHandle id);

    Parameters:

    ResponseCode: This parameter contains the actualUDP socket event which has occurred. This parametercan have the following values :

    ED_INFO_LISTEN_SET: This event indicates thatthe listening UDP socket has been successfullycreated and now it is waiting for any remote entity(UDP client) to connect to it. This event is relevantonly for a UDP server socket.

    ED_OK_UDP_CLOSED: This event indicates thatthe UDP client/server socket has been successfullyclosed.

    ED_INFO_WAITING_FOR_DATA: This eventindicates that the UDP client has been successfullyopened and is ready to send data to the server. Ifthis event is received on the server side, it indicatesthat it has received a datagram from some client.

    ED_ERR_DISTANT_DNS: This error indicates thatthe Remote server name has not been mapped byDNS. TCP/IP stack is not able to reach the primaryand secondary DNS servers or a wrong serveraddress has been filled in.

    ED_ERR_STACK_INTERNAL: This error indicatessome internal IP stack error.

    ED_ERR_LISTEN_STOP: This event indicates that

    a listening UDP socket has been cancelled usinged_SocketLUDPStop () API. A listening socket isthe one which is listening for incoming clientrequests and has not received any such requestyet.

    ED_ERR_NETWORK_KO: This event indicatesthat the WISMO module is not connected to thenetwork when an attempt was made to open a UDPsocket.

    ED_ERR_GPRS_SESSION_LOST: This eventindicates that the GPRS session has lost activation(The module is no longer connected to GPRS).This event occurs in case, GPRS connection is lostwhile a TCP socket was open in client or servermode.

    id: This parameter is always set toED_ID_UDP_SOCKET.

    Remarks: ED_ERR_LISTEN_STOP event is received when a

    listening UDP socket is closed usinged_SocketLUDPStop() API. Once the listeningserver socket has made a connection with a clientUDP guess UDP) socket, it becomes active anded_SocketLUDPStop API cannot be used to closethis socket.

    When a listening socket is closed, firstED_OK_UDP_CLOSED event will be received andthen ED_ERR_LISTEN_STOP event will bereceived.

  • 7/21/2019 Using TCP and UDP Under Open-At

    9/13

    Using TCP and UDP under Open ATTM

    WM_ASW_OAT_APN_017-001

    2004 All rights reserved Page: 8 / 11This document is the sole and exclusive property of WAVECOM. Not to be distributed or divulged without prior written agreement.Ce document est la proprit exclusive de WAVECOM. Il ne peut tre communiqu ou divulgu des tiers sans son autorisation pralable.

    A

    P

    P

    L

    IC

    A

    T

    ION

    NOT

    E

    A

    P

    P

    L

    ICA

    T

    ION

    NOT

    E

    AP

    P

    LIC

    A

    T

    ION

    NOT

    E

    pfDataHnd: This function is called by the IP library toforward the data received to the application. Thiscallback function has the following prototype :

    typedef u16 (*ed_DataHandler_f) (u16 DataLen, u8*Data, TeDHandle id);

    Parameters:

    DataLen: This parameter is the length of datawhich has been received in the data handler.

    Data: This parameter is the pointer to the actualdata received.

    id: This parameter is always set toED_ID_UDP_SOCKET.

    Return Value:The return value of this function indicates the number ofbytes processed by the application. The applicationshould return the appropriate number representingthis value. The remaining bytes will be processed inthe next call to this function.

    pfDataRequest: This function is called by IP library

    when a client UDP socket is opened. This function asksfor the data to be sent by the user. Inside this function,calls to ed_SendData functions can be made with thefollowing prototype :

    typedef void (* ed_DataRequest_f) (u16 MaxLen,TeDHandle id) ;

    Parameters:

    MaxLen: This parameter specifies the maximumdata length which can be sent in this call to thepfDataRequest function. This length should betaken care of in any call to ed_SendData function tosend data to the peer entity.

    id: This parameter is always set toED_ID_UDPSOCKET.

    Remarks: In case of UDP server socket, this function

    (pfDataRequest ()) is called when a UDPdatagram is received by it (sent to it by someclient).

    In case of UDP client socket, this function is calledwhen the client socket is opened.

    Data should preferably be sent from this callbackfunction because ed_SendData() API will besuccessful only when a prior call has been made topfDataRequest () API. In case, no call was madeto pfDataRequest and an attempt is made to senddata using ed_SendData, error code -51(ED_ERR_INVALID_CALL) will occur. Hence, it ispreferable to call ed_SendData from within thisfunction. However, the application is free to use itfrom outside (by subscribing to some commands) incase provision is made to take this factor intoaccount.

    The length of data to be sent (usinged_SendData ()API) should be less than or equalto the MaxLen parameter of pfDataRequestcallback function.

    Return Values (of pfDataRequest Callback function):NONE

    Return Values:

    0is returned on success.

    ED_ERR_NO_TCPIPis returned if TCP/IP feature is notenabled on the product.

    ED_ERR_NOT_INIT is returned if ed_Init () API is notcalled prior to calling this API.

    ED_ERR_INVALID_ARG is returned if one of thearguments has invalid or NULL value.

    ED_ERR_STACK_BAD_CONFIG is returned if IPconnectivity library has incorrect configuration.

    ED_ERR_PHY_NOT_ACTIVATED is returned if IPconnectivity library physical connection is not activated.

    This event occurs when physical connection (GPRSconnection or GSM call) is not active at the time of datatransfer.

    ED_ERR_STACK_BUSY is returned if another IPconnectivity library application is already running.

    2.4.3 Sending Data and Closing UDP Client/Server

    eDLib provides APIs to exchange data from one peer to anotherpeer. ed_SendData() API should be used to send data and/or toclose the UDP Client/Server socket. This API has the followingprototype:s8 ed_SendData (u8 *Data, u16 DataLen, bool bEnd);Parameters:

    Data: Pointer to data to send.

    DataLen: Length of data to send.

    bEnd: Boolean variable which indicates whether end ofdata transmission has reached or not. If bEnd=TRUE, itindicates that the IP connectivity library has received thelast block of data to send for current session and it willnot request data anymore (by calling pfDataRequest ()

    API). However, if bEnd= FALSE, it is an indication thatmore data has to been sent by the application andpfDataRequest function will be called again which willask user for more data to send.

    Return Values:

    0is returned on success.

    ED_ERR_NO_TCPIPis returned if TCP/IP feature is notenabled on the product.

    ED_ERR_NOT_INIT is returned if ed_Init () API is notcalled prior to calling ed_SendData API.

    ED_ERR_INVALID_CALL is returned if ed_SendDataAPI cannot be called now because pfDataRequest ()function was not called by IP connectivity library.

    ED_ERR_INVALID_SIZE is returned if DataLenparameter of ed_SendData function is greater thanexpected.

    Remarks: The flag bEnd provides a way to close the UDP

    client/server socket. This flag should be used toclose any of these sockets. If this flag=TRUE, itindicates that the last block of data has been sentand the socket will close.

    ed_SendData() can be called from pfDataRequestAPI and the MaxLen parameter of pfDataRequestAPI must be taken into account before sendingdata using ed_SendData API.

    eDLib provides one more API which can be used to send UDPdatagrams. Following is the prototype of this API:s8 ed_SendDataExt (u8 *Data, u16 DataLen, bool bEnd,

    TeDHandle id);This API is usually used for sending data associated with TCPsocket services. If the id parameter is set to ED_ID_UDPSOCKET,then this API can also be used for UDP socket services. This APIalso performs the same task as is performed by ed_SendData ()

    API. Please refer section 2.3.3for more details on this API.

    2.4.4 To Close a listening UDP Server SocketIn order to close a listening UDP server socket the following APIshould be used:

  • 7/21/2019 Using TCP and UDP Under Open-At

    10/13

    Using TCP and UDP under Open ATTM

    WM_ASW_OAT_APN_017-001

    2004 All rights reserved Page: 9 / 11This document is the sole and exclusive property of WAVECOM. Not to be distributed or divulged without prior written agreement.Ce document est la proprit exclusive de WAVECOM. Il ne peut tre communiqu ou divulgu des tiers sans son autorisation pralable.

    A

    P

    P

    L

    IC

    A

    T

    ION

    NOT

    E

    A

    P

    P

    L

    ICA

    T

    ION

    NOT

    E

    AP

    P

    LIC

    A

    T

    ION

    NOT

    E

    s8 ed_SocketLUDPStop (ed_ResponseCbk_f ResponseCbk);

    Parameters:

    pfResponseCbk: This is the callback function which iscalled by IP library to indicate various socket relatedevents (like socket close, or some error condition). Formore information on this callback, please refer section

    (2.3.2).

    Return Values:

    A 0 is returned on success.

    ED_ERR_NO_TCPIPis returned if TCP/IP feature is notenabled on the product.

    ED_ERR_NOT_INIT is returned if ed_Init () API is notcalled prior to calling ed_SocketLUDPStop API.

    ED_ERR_INVALID_ARG is returned if one of thearguments has invalid or has NULL value.

    ED_ERR_NO_LISTEN if ed_SocketLUDPStop is calledwhen no socket is opened in listening mode.

    Remarks: A l istening socket is the one which is listening

    for some incoming datagrams and has notreceived any.

    Once a listening socket received a datagramfrom a client, it becomes active and cannot beclosed by ed_SocketLUDPStop () API. Tostop the active socket, use ed_SendData(section 2.4.3).

    Reference:

    Open ATTM

    IP Connectivity Library Guide (eDLib v3.00)

    3 CUSTOM AT COMMANDS

    3.1 Commands for TCP Socket

    The following AT commands are included in the Open ATTM

    application for TCP client/server sockets.

    AT Command Syntax

    AT+APNPARAMS

    Command Description: This command is used to generate amenu which would display the commands that can be used to setthe APN parameters (like APN server, APN User-name and APNpassword). Please note that the default value of all theseparameters is empty string (). The APN parameters should be setonly to override this default value ().

    AT Command Syntax

    AT+APNSERV =

    Parameters Values Description

    Any validstring

    This parameter stands forthe APN server name.

    Command Description: This command is used to set the APNserver string. The default value of this parameter (APN serverstring) is empty string (). The command(AT+APNSERV=) can be used to override thisdefault value.

    AT Command Syntax

    AT+APNUN =

    Parameters Values Description

    Any valid

    string

    This parameter stands for

    the APN user name.

    Command Description: This command is used to set the APNuser name. The default value of this parameter is empty string ().This command should be used to override this default value.

    AT Command Syntax

    AT+APNPW =

    Parameters Values Description

    Any validstring

    This parameter representsthe APN password

    Command Description: This command is used to set the APNpassword string. The default value of this parameter is empty string(). This command should be used only to override this defaultvalue.

    AT Command Syntax

    AT+START

    Command Description:This command is used to connect to theservice provider and get an IP address. This command utilises the

    APN parameters set previously. So, correct APN parameters mustbe entered prior to executing this command.

    AT Command SyntaxAT+LTCPSTART

    Command Description: This command is used to start the TCPserver socket in listening. Before starting the server socket, thiscommand prompts the user to enter the port (using AT+LPORTcommand) on which the TCP server will listen.

    AT Command Syntax

    AT+LPORT =

    Parameters Values Description

    1-65535 Port on which TCP Serverwill listen client TCPconnections.

    Command Description: This command is used to specify the port

    on which the TCP server socket will listen.

    AT Command Syntax

    AT+LTCPSTOP

    Command Description: This command is used to stop thelistening TCP server socket. However, for this command to beeffective, the TCP server socket must not have a connection withsome TCP client socket. This is because, if some client connectsto the TCP server socket, the TCP server socket becomes active(does not remain in listening state) and cannot be closed using

    AT+LTCPSTOP command. To stop this connection use AT+CTCPcommand (described later).

    AT Command Syntax

    AT+OTCP

    Command Description: This command will start a client TCPsocket. After this command is executed, the customer will beprompted to enter port and IP address of TCP server (using

    AT+SPORT and AT+IP commands).

    AT Command Syntax

    AT+SPORT =

    Parameters Values Description

    1-65535 The on which the TCPserver socket is listeningwith whom the connectionis to be made.

    Command Description: This command will set the destinationTCP server port for a client TCP socket. For example, AT+SPORT

    = 80.

    AT Command Syntax

  • 7/21/2019 Using TCP and UDP Under Open-At

    11/13

    Using TCP and UDP under Open ATTM

    WM_ASW_OAT_APN_017-001

    2004 All rights reserved Page: 10 / 11This document is the sole and exclusive property of WAVECOM. Not to be distributed or divulged without prior written agreement.Ce document est la proprit exclusive de WAVECOM. Il ne peut tre communiqu ou divulgu des tiers sans son autorisation pralable.

    A

    P

    P

    L

    IC

    A

    T

    ION

    NOT

    E

    A

    P

    P

    L

    ICA

    T

    ION

    NOT

    E

    AP

    P

    LIC

    A

    T

    ION

    NOT

    E

    AT+IP =

    Parameters Values Description

    Valid stringrepresentingan IPaddress

    IP address of the serverwith whom TCP socketconnection is to be made.

    Command Description: This command will set the destinationTCP server socket IP address for a client TCP socket. Thiscommand should be used after AT+PORT command is used. Forexample, AT+IP = 10.16.22.149. In case, some error occurs instarting TCP client socket, then AT+OTCP command should begiven to start the whole process once again.

    AT Command Syntax

    AT+SENDDATA=

    Parameters Values Description

    Any validstring

    The data to be sent overthe established TCP socketconnection.

    Command Description: This command is used to send data tothe remote peer. The length of data to be sent should be less than

    or equal to the MaxLen parameter of the ed_DataRequest_fcallback function (described later in this application note). Forinstance, AT+SENDDATA= test.

    AT Command Syntax

    AT+CTCP

    Command Description: This command is used to close theclient/active server socket.

    3.2 Commands for UDP Socket

    Unlike application for TCP socket, UDP socket application makesconnection with the APN server and provides an IP address to theuser. To change the APN parameters, some modifications in theUDP sample application code should be made (like changing APNserver, APN user name and APN password). This exemplifies adifferent approach than TCP sockets. Following commands aresubscribed in the UDP socket application. It should be noted thatthese commands should be issued only after receiving an IPaddress from the network service provider.

    AT Command Syntax

    AT+LUDPSTART

    Command Description: This command starts a UDP serversocket on port 80. No IP filtering is specified.

    AT Command Syntax

    AT+LUDPSTOP

    Command Description: This command will stop the UDP serversocket started on port 80. However, for this command to beeffective, the UDP server socket must not have received any datafrom a client UDP socket. If UDP server receives data from someclient socket, it becomes active (does not remain in listening state)and cannot be closed using AT+LUDPSTOP command. To stopthis connection use AT+CUDP command (described later).

    AT Command Syntax

    AT+OUDP

    Command Description: This command will start a client UDPsocket. After this command is executed, the customer will beprompted to enter port and IP address of UDP server (using

    AT+PORT and AT+IP commands which are described below).

    AT Command SyntaxAT+PORT =

    Parameters Values Description

    1-65535 Port on which server UDPsocket is listening to whichconnection is to be made.

    Command Description: This command will set the destinationUDP server port for a client UDP socket. For instance, AT+PORT =240.

    AT Command Syntax

    AT+IP =

    Parameters Values Description

    A validstringrepresentingan IPaddress

    This parameter representsthe IP address of the UDPserver socket with whomUDP socket connection isto be made.

    Command Description: This command will set the destinationUDP server socket IP address for a client UDP socket. Thiscommand should be used after AT+PORT command is used. Forinstance, AT+IP = 10.16.29.54.

    AT Command SyntaxAT+CUDP

    Command Description: This command is used to close the UDPclient/active UDP server socket. An active UDP server socket isthe one which has successfully exchanged data with one of theclient sockets and is not in listening state.

    AT Command Syntax

    AT+SENDDATA

    Command Description: This command is used to send data tothe remote UDP peer. The data constitutes of the text stringHello.

    4 EXAMPLES

    Example 1 TCP socket

    Action Response Action

    Power up Waiting for+WIND: 4.Pleasewait..

    Module waiting for+WIND: 4 indication.

    Reception of+WIND: 4

    +WIND: 4received.Pleasewait..

    Tries to attach toGPRS. After successfulGPRS connection,main menu is shown onTerminal Emulator.

    AT+APNPARAMS ------------- Submenu is drawn onscreen.

    AT+APNSERV=

    server_string

    OK New ApnServ

    Parameter is set.AT+APNUN=user_name

    OK New ApnUn parameteris set.

    AT+APNPW=password

    OK New ApnPw parameteris set

    AT+START OKTrying toretrieve IPinformation.Pleasewait...

    Connecting withservice provider usingthe APN parameters toreceive an IP address.

    AT+LTCPSTART OKEnter

    AT+LPORTto specifylistening

    port

    Prompts for port onwhich TCP serversocket has to bestarted.

    AT+LPORT=

    OK Starts TCP serversocket on the port

  • 7/21/2019 Using TCP and UDP Under Open-At

    12/13

    Using TCP and UDP under Open ATTM

    WM_ASW_OAT_APN_017-001

    2004 All rights reserved Page: 11 / 11This document is the sole and exclusive property of WAVECOM. Not to be distributed or divulged without prior written agreement.Ce document est la proprit exclusive de WAVECOM. Il ne peut tre communiqu ou divulgu des tiers sans son autorisation pralable.

    A

    P

    P

    L

    IC

    A

    T

    ION

    NOT

    E

    A

    P

    P

    L

    ICA

    T

    ION

    NOT

    E

    AP

    P

    LIC

    A

    T

    ION

    NOT

    E

    specified. No IP filteringis done.

    AT+LTCPSTOP Listeningsocketclosedsuccessfully.

    Stops the listeningsocket (which has notyet establishedconnection).

    AT+OTCP OKEnter

    AT+SPORTto specifyserversocket port

    Prompts for the serversocket port

    AT+SPORT=

    OKEnter AT+IPto specifyserver IP

    Sets the server portand prompts server IP.

    AT+IP= OKTrying toestablishconnectionwith theserver..

    Sets the server IPaddress and tries tomake connection withserver socket.Successful connectionwill generate TCPSession Startedresponse.

    AT+SENDDATA=test

    TCP packetsentsuccessfully

    Sends the dataspecified in theargument as TCP data.

    AT+CTCP TCP socketclosedsuccessfully

    Closes (terminates) anactive TCP socketconnection.

    Example 2 UDP Sockets

    Action Response Action

    Power UP Waiting for+WIND:4

    Waiting for +WIND:4 indication.

    Reception of+WIND: 4

    +WIND: 4received. Please

    wait.

    Tries to attach toGPRS. After GPRS

    connect, uses APNparameters (set inapplication) toreceive an IPaddress and drawsa main menu.

    AT+LUDPSTART OKUDP socketstarted inlistening mode.

    Starts a UDPsocket on port 80.No IP filtering isspecified.

    AT+LUDPSTOP Listening Socketclosedsuccessfully.

    Closes thelistening UDPsocket (which hasnot yet exchangeddata with any clientsocket).

    AT+OUDP OKEnter AT+PORTto specify serverport.

    Prompts for theport on which UDPserver is listening.

    AT+PORT= OKEnter AT+IP tospecify serverIP.

    Sets the serverport to theargument specifiedin the command.Prompts for theserver IP.

    AT+IP= OKUDP sessionstarted.

    Sets the server IPto the valuespecified in theargument. Alsostarts the clientUDP session.

    AT+SENDDATA UDP packetsentsuccessfully.

    Sends the UDPpacket having thestring Hello to the

    peer UDP socket.

    AT+CUDP UDP socketclosedsuccessfully.

    Closes the activeUDP server/clientsocket.

    5 REFERENCE HARDWARE

    No reference hardware is necessary with this application note.

    6 PACKAGE DELIVERABLES

    This application note is delivered as a single compressed ziparchive as follows:

    Filename Description

    WM_ASW_OAT_APN_017-001.zip

    Application Note

    6.1 DOCUMENTATION

    WM_ASW_OAT_APN_017-001.doc is the file for application note.

    6.2 SOFTWARE

    List all of the files that will be included in the zip file.

    Filename Description

    sample_tcp.c OAT source file for TCP sockets.

    sample_udp.c OAT source file for UDP sockets.

    7 SOFTWARE COMPATIBILITY MATRIX

    List all current software configurations and compatibility with thisapplication note.

    Core Open ATTM

    IP Compatibility

    3.41c V2.10c V2.10 No

    5.41c V2.10c V2.10 No

    6.41c V2.10c V2.10 Yes but with modificationsin the application.

    650a V3.01 V3.0 YES

    8 SUPPORT

    For direct clients: contact your Wavecom FAEFor distributor clients: contact your distributor FAEFor distributors: contact your Wavecom FAE

    9 DOCUMENT HISTORY

    Level Date History Author

    001 06/06/2005 Creation Wavecom Support Consultant

    10 LEGAL NOTICELICENCE RIGHTS

    Wavecom Asia Pacific Ltd hereby grant licence to users of their Open AT

    TM

    development environment to use the source code in thiselectronic file for the sole use of developing GSM, GSM/GPRS or GSM/GPRS/GPS cellular applications compatible with Wavecomproducts. The source code may be modified by any Open AT

    TMdeveloper providing the application is not intended to be malicious or

    detrimental to cellular operators or consumers of the application in any way. The licence also grants permission to copy and distributethis source code so long as this licence header is maintained in all source code files. You hereby undertake to use the Software foryour interim development purposes only and under no circumstances shall you us e the Software for commercial purposes. For theavoidance of doubt, the Software may not be sold for a fee on diskette or CD-ROM, either alone or as part of a collection with otherproducts without prior written consent from Wavecom.

    DISCLAIMER OF WARRANTYThis Software is provided free of charge on an 'as is' basis. No warranty whether expressed or implied is given by Wavecom in relationto the Software of the uses to which it may be put by you, the user, or its performance or merchantability, fitness or suitability for anyparticular purpose or conditions; and/or that the use of the Software and all documentation relating thereto (the Documentation) bythe Licensee will not infringe any third party copyright or other intellectual property rights. Wavecom shall furthermore be under noobligation to provide support of any nature for the Software and the Doc umentation.

    LIMIT OF LIABILITYIn no event shall Wavecom be liable for any loss or damages whatsoever or howsoever caused arising directly or indirectly inconnection with this licence, the Software, its use or otherwise irrespective of whether Wavecom has had advance notice of thepossibility of such damages or not by your use of the Software. Notwithstanding the generality of the foregoing, Wavecom expresslyexcludes liability for indirect, special, incidental or consequential loss or damage which may arise in respect of the Software or its use,or in respect of other equipment or property, or for loss of profit, business, revenue, goodwill or anticipated savings.

    INTELLECTUAL PROPERTYFor the avoidance of doubt, no right, title or interest in any intellectual property right in respect of the Software shall pass to you. Anyand all intellectual property rights in respect of the Software and Documentation shall at all times remain the sole and exclusiveproperty of Wavecom. The licence grant shall not include Intellectual Property not wholly owned by W avecom and the customer shallexercise due diligence to ensure that the use of the information in this document does not infringe any patents in the c ountry of origin.

  • 7/21/2019 Using TCP and UDP Under Open-At

    13/13

    WAVECOM S.A. - 3, esplanade du Foncet - 92442 Issy-les-Moulineaux Cedex - France - Tel: +33 (0)1 46 29 08 00 - Fax: +33 (0)1 46 29 08 08WAVECOM, Inc. - 4810 Eastgate Mall - Second Floor - San Diego, CA 92121 - USA - Tel: +1 858 362 0101 - Fax: +1 858 558 5485WAVECOM Asia Pacific Ltd. - 5/F, Shui On Centre - 6/8 Harbour Road - Hong Kong, PRC - Tel: +852 2824 0254 - Fax: +852 2824 0255

    ,W

    AVECOM,

    WISMO,

    MUSEPlatform,andcertainothertrademarksandlogosappearingonthisdocument,arefiledorregisteredtrademarksofWavecomS.A.

    inFranceorinothercountries.

    Allothercompanyand/orproductnamesmentionedmaybefiledorregisteredtrademarksoftheirrespectiveowners.