Communication services are an integral aspect for mobile devices. This course gives an high-level overview of the different available options on how a mobile phone can get in contact with other electronic devices.
Contents
* Communication overview
* Sockets
* HTTP
* Serial communication
* Infrared / Bluetooth
* Messaging
* Telephony
5. Communication Andreas Jakl, 2008 5 Serial communicationframework TCP/IP Stack HTTP transportframework Sockets framework Telephonyframework (WAP stack) Bluetooth stack Messaging Protocol support (incl. MMS, SMTP, POP3, IMAP) Infrared stack Telnet and FTP engines SMS and EMS stack
6. Basic Architecture Many requirements: Hardware: IR present?, Bluetooth? Operator: TCP/IP supported?, MMS? … Four different frameworks(Communications Servers) Plug-in modules implement protocols Example: Socket-Connection with TCPFramework (Comm. Server): protocols through socketsPlug-in module: TCP Andreas Jakl, 2008 6
7. Communications Servers Most are implemented as Servers (Client/Server!) Four communication servers: Sockets: Communication using addressable end points, using protocols like TCP/IP Serial comms: Simple serial communication, using IR or Bluetooth, RS-232 (not supported by S60) Messaging: Send, receive and save messages, using protocols like email or SMS Telephony: Control telephone calls and services Andreas Jakl, 2008 7
9. Sockets Socket Logical communication endpoint between 2+ software processes Communication Peer-to-Peer: Two similar processes communicate Client-Server: Different roles, e.g. web server & browser Can be used for: TCP/IP, Bluetooth, Infrared, USB Andreas Jakl, 2008 9
10. Characteristics Communication Domain Address family / format of the socket e.g. internet socket (KAfInet): address + port number Socket Type Typically: Streaming (connected) – KSockStream Datagram (connectionless) – KSockDatagram Transport Protocol e.g. TCP/IP (KProtocolInetTcp) Andreas Jakl, 2008 10 Typical Symbian OS call: iSocket.Open(iSocketServ, KAfInet, KSockStream, KProtocolInetTcp);
11. Connection Connection-oriented – “reliable” First establishes end-to-end-connection, then sends data Connection is present can check delivery order, arrival, errors, ... Connectionless – “unreliable” Requires destination address each time data is sent (datagrams) Each received packet is treated independently No guarantees on order, duplication, delivery Andreas Jakl, 2008 11
12. Symbian OS Sockets C++ Socket Framework Similar to BSD C-based socket API Transport-Independent Allows: Internet protocol suite, Bluetooth, USB, IR Lower communication layers handled by communications-server Andreas Jakl, 2008 12
13. Sockets Framework Sockets Server (esock.exe) Provides end-to-end communication Protocols supplied by plug-ins, examples: TCP/IP Bluetooth (L2CAP, RFCOMM) IR (IrDA, IrTinyTP, IrMUX) SMS Protocol modules (PRTs) (un)loaded as required Can contain multiple protocols e.g. TCPIP.PRT contains UDP, TCP, ICMP, IP, DNS Andreas Jakl, 2008 13 esock.exe tcpip.prt irda.prt
14. Sockets – Structure Andreas Jakl, 2008 14 myApp.exe Calling client Client interface for theSocket Server: RSocketServ Socket itself: RSocket Socket-implementation(Client-side) esock.dll Client-Servercommunication (via kernel) Process Boundary esock.exe Socket Server … TCP/IP(tcpip.prt) IrDA(irda.prt) Protocol Modules(Plug-Ins)
15. Important Components RSocketServ Creates a session with the socket server Communication channel to the socket server RSocket (Subsession of RSocketServ) Every connection to a server needs an RSocket-Subsession RHostResolver (Subsession of RSocketServ) Name resolution services (DNS Lookup) RConnection (Subsession of RSocketServ) Selecting an Internet Access Point Supports Multihoming (several network interfaces active at the same time) If not used by client app: automatic implicit connection TProtocolDesc Query supported socket protocols Andreas Jakl, 2008 15 RSocketServ RSocket RHostResolver RConnection
16. Stepsfor TCP/IP Create a connectiontotheSocket Server (Check protocols)* (Choose Internet Access Point)* (Send DNS-Request)* (Close connectionto DNS-Resolver)* OpenTCP Socket Connection request + target IP Data transfer Close socket (Close Connection)* Close Socket Server connection Andreas Jakl, 2008 16 RSocketServ RSocketServ / TProtocolDesc RConnection RHostResolver Asynchronous RSocket RSocket Asynchronous RSocket Asynchronous RSocket RConnection RSocketServ * optional step
17. RSocketServ Communicates with the socket server Used for: Establishing subsessions for RSocket & RHostResolver RSocketServ does not send/receive data or establish connections! To use it: Instantiate an object of RSocketServ Establish a session with the socket server: RSocketServ::Connect() Cleanup: RSocketServ::Close() automatically closes all subsessions ... but it’s recommended to close sockets first Andreas Jakl, 2008 17 RSocketServ
18. RHostResolver Generic interface for protocol-specific host-resolution services Example: IP address 81.89.143.203 hard to remember www.symbian.com is much more pleasant Domain Name System (DNS) translates this Allows: Converting server name to IP address: RHostResolver::GetByName() Getting hostname of the local device IR + BT: Discover other devices in range Generic interface – available methods depend on protocol module! Andreas Jakl, 2008 18 RHostResolver
19. RSocket Endpoint for socket-based communication Each instantiated object represents a single socket Allows: Socket opening Active connecting Read / write data from / to a protocol Passive connections (listen/accept-model) Andreas Jakl, 2008 19 RSocket
20. Socket Lifecycle Andreas Jakl, 2008 20 Start Closed Open(RSocketServ&) Open(RSocketServ&, ...) Open Blank CancelConnect()(if reconnectable) Listen() Connect() Listening Connecting CancelConnect()non-reconnectable Accept() Called on listening socket with blank socket parameter Protocol disconnects reconnectable socket Error Connected Shutdown() Protocol disconnects non-reconnectable socket Shutting down Discon-nected RSocket::Close() can be called from any state and will return the socket to the Closed state, cleaning up any resources or outstanding requests. Shutdown(EImmediate) Dead = all operations will return errors. Close() is the only available operation.
22. Active Connection* – Initialization Connect to the socket server RSocketServ::Connect() Socket server needed to create subsessions for RSocket and RHostResolver Andreas Jakl, 2008 22 Connectionless & Connected * an active connection is initiated by your program.Your program can also wait to receive connections from a peer (“passive connection”)
23. Configuring & Connecting Assign a local address to a connectionless socket RSocket::Open() RSocket::Bind() Connectionless Configure socket with address of the remote socket tied together until the end RSocket::Connect() [asynchronous] RSocket::Bind() called automatically (if not done manually) Andreas Jakl, 2008 23 Connected
24. Reading Receive data + address of the sending endpoint RSocket::RecvFrom() Connectionless Asynchronous requests. Receive buffers: 8-bit descriptors.Advantage: current & max. length are always known! Complete when data is available: RSocket::RecvOneOrMore() Complete when entire descriptor is filled: RSocket::Recv() – should not be used for TCP Andreas Jakl, 2008 24 Connected
25. Writing Always needs the address of the end point RSocket::SendTo()Parameters: target address, buffer to send, flags Connectionless Asynchronous requests. Does not need endpoint because of established connection RSocket::Write() – sends the entire descriptor RSocket::Send() – allows control over amount of data sent & flags Andreas Jakl, 2008 25 Connected
26. Closing Recommended: Cancel pending requests RSocket::CancelAll() Close synchronously (releases all resources) RSocket::Close() Connectionless Same as above, but you should disconnect before closing the socket using Close() RSocket::Shutdown() – asynchronous, takes a flag how to close the socket (e.g. EStopInput = Stop socket input and complete when output is stopped) Andreas Jakl, 2008 26 Connected
28. Socket Type Andreas Jakl, 2008 28 RSocket::Open(RSockServ&, addrFamily, sockType, protocol)
29. Send / Receive Data Each task is an asynchronous process Callback (Success?) in RunL() Send: iSocket.Write(iWriteBuffer, iStatus);SetActive(); Receive: iSocket.RecvOneOrMore(iBuffer, flags, iStatus, iLength);SetActive(); Andreas Jakl, 2008 29 ContaindatasentbyAsynchronous Service Provider after requestcompletition
30. Secure Sockets Symbian OS supportsclient-sideofSSLandTLS Implementation: Create connectionasalwaysusingRSocket Create CSecureSocketobjectbased on theconnection Transfer datathroughCSecureSocketinstance Andreas Jakl, 2008 30
31. S60 Sockets Example Andreas Jakl, 2008 31 C:ymbian.1a60_2nd_FP3eries60Exockets
33. HTTP HTTP Client API since Symbian OS v7.0 S60 implements HTTP 1.1 compatiblestack Framework forhandlingTCP/IP-Communicationwith HTTP servers High-Level API Andreas Jakl, 2008 33
34. HTTP – Overview Andreas Jakl, 2008 34 SessionCommunicationsettings … TransactionHandling of messages Transaction TransactionsubmitsRequestHeader, Body Server GPRS, UMTS, … Callback(Transaction-Interface)ResponseHeader, Body
35. HTTP – Session Defines Settings for communication HTTP protocol, encoding and transport (Proxy, …) Contains 1+ Transactions, who share the connection HTTP-terms (GET, User-Agent, …) defined in StringPool HashMap for Strings Application doesn’t have to define strings itself more efficient, faster comparison, … RStringPoolstrP = iSess.StringPool();RStringF method = strP.StringF(HTTP::EGET, RHTTPSession::GetTable()); Andreas Jakl, 2008 35
36. HTTP – Transaction Defines exchange of messages between client / server Advanced functionality: Can be influenced through Filter (MHTTPFilter) Used for caching, automated handling of specific status codes (redirection, authentication, …) Not necessary for standard application Andreas Jakl, 2008 36
37. Procedure Set up Session (RHTTPSession) When using standard protocol: no additional parameters Create Transaction (RHTTPTransaction) Exchange of messages between client and server Most likely: Client request Server response Open through session Define Request (RHTTPRequest) Set message for the request Contains URI for the request, target for call-back and type of the request (GET, POST) Andreas Jakl, 2008 37
38. Messages – Request Header (RHTTPHeaders) Information about transaction, message or client/server itself Usually defined by the application: UserAgent (e.g. browser name) Accepted content for the response (e.g. „text/*“) Other properties set automatically (Content-Length, Host, …) Body (MHTTPDataSupplier) When using POST: form data Andreas Jakl, 2008 38
40. Procedure (Continued) Send Request (iTransaction.SubmitL()) Asynchronous processing implemented in Symbian OS HTTP Stack classes Status callbacks sent to MHFRunL() Most of the time you’ll need to convert from 8bit to 16bit Unicode Andreas Jakl, 2008 40
41. Procedure – Finish Process response (RHTTPResponse, equivalent to RHTTPRequest-Message) Several call-backs sent: EGotResponseHeaders Contains header of server response, e.g.: HTTP/1.1 200 OKContent-Length: 354[…] EGotResponseBodyData (if successful) Called 1..n times, until data is received completely Manually combine fragments to complete response EResponseComplete Called when data is fully received Andreas Jakl, 2008 41
42. Cleanup (if necessary) Cancel transaction iTransaction.Cancel() – cancel active transaction iTransaction.Close() – cancel + free resources of the transaction Close session: iSession.Close() – includes all above options Andreas Jakl, 2008 42
44. Overview – Serial Comm. Low-Level, Point-to-Point Technology Managed by the Serial Communications Server (C32) Plug-ins for data transfer (called CSY = DLL) Infrared Bluetooth (RS232 – supported by Symbian OS, not by S60) Requires port configuration (Baud-Rate, Parity, …) Andreas Jakl, 2008 44
45. Serial Connections Load serial device drivers Start Comms-Server Connect to Comms-Server Load Comms-Module (CSY – use Ir / Bt?) Open serial port Configure port Read / write data through port Close port Andreas Jakl, 2008 45
48. Useable through IrDA Sockets API or IrDA Serial API Server Protocols Services Infrared Andreas Jakl, 2008 48 Application Serial comms server Socket server IrCOMM IrTinyTP IrMUX IrOBEX IrLAN
50. Bluetooth Bluetooth-Support through Socket Server Plug-in Allows using standard Socket APIs Point-to-Point and Multipoint supported S60 3rd Edition+: Bluetooth 1.2 Very complex topic … … however, there are many example programs in the SDK! Andreas Jakl, 2008 50
51. BT Host (SW) Bluetooth-Stack Andreas Jakl, 2008 51 Radio Frequency Comm. Emulates RS-232 through L2CAP protocol. Session Discovery ProtocolAllows searching for other devices and services. Required for setting up communication. RFCOMM protocol SDP L2CAP protocol Logical Link Control And Adaption Protocol Allows detailled control of the connection. Defines type of data transfer. HCI Driver Host Controller InterfaceCommunication with HW Host ControllerTransport Layer BT Host Controller (HW) HCI Firmware Link Manager ProtocolManages behaviour of the wireless connection. Security mechanisms. Link Manager Protocol (LMP) Baseband Link Controller (LC) Bluetooth Radio
52. Access to Session Discovery Protocol Architecture Andreas Jakl, 2008 52 Set security requirements (authentication, authorisation, encryption) BT Sockets BT Security Manager Sockets Client BT Service Discovery Agent Client Server Sockets Server BT Service Discovery DB BT Sockets Module Query services from remote device. Get Attributes for specific service. Host Controller Interface
53. Bluetooth – Sockets, Security Access through Socket classes (e.g. RSocket) Specialised extensions, e.g.: TBTDevAddr: BT device addresses TInquirySocketAddr: For search using RHostResolver BT Security Manager Enables specification of security settings: User authorization, authentication and encryption required for connection? Andreas Jakl, 2008 53
54. Bluetooth – Services BT Session Discovery Protocol (SDP) through 2 APIs: BT Service Discovery Agent:Allows the user to query services and their attributes from remote devices BT Service Discovery Database:Local service can add ist attributes so that it can be found by other devices Andreas Jakl, 2008 54
55. Bluetooth – Serial, OBEX Serial Communication Plugin of the Serial Server Only for outgoing connections (incoming through RFCOMM, using Sockets) For legacy applications and the Serial Port Profile OBEX Protocol (Object Exchange) Exchange objects like vCards or appointments API (CObexClient/CObexServer) for session through Bluetooth or IrDA Andreas Jakl, 2008 55
57. Messaging Framework for Multi-Protocol-Messaging Plug-ins for individual protocols (MTM) Message Server Manages entries, folders and messages in a hierarchical structure Controls data access Delegates protocol-specific requests to server-side MTMs Access through Session (CMsvSession) Andreas Jakl, 2008 57
58. Root Services Message Server – Architecture Andreas Jakl, 2008 58 Root … Mail Service SMS Service Local Service Messages andfolders Outbox Sent Drafts Inbox Customfolders .. Sub-folders Messageentry Messageentry Messageentry Attach-ment
59. Entries – Architecture Andreas Jakl, 2008 59 CMsvEntryEntry handler Represents a node in the message server hierarchy, provides means to access the current item and to navigate through the tree CMsvStoreEntry Store Stores message body text, headers, … TMsvEntryIndex Entry Generic summary of the message, containing most important info (type, date, size, read/unread, …) TMsvIdEntry ID Unique ID of the entry
60. MTMs Protocol Plug-Ins for the Message Server Handle lower level communication (TCP/IP, …) Offer two APIs: Server and Client-API Pre-installed for: SMS (EMS), MMS, POP3, IMAP4, SMTP, OBEX, BIO Messaging (vCards, configuration SMS) Additionally available for all MTMs: Simple, generic Client-API User Interface Wrapper classes Extensible: e.g. Flickr MTM example in the “Symbian OS Communications Programming, 2nd Edition”-book (Iain Campbell, John Wiley & Sons, 2007). Andreas Jakl, 2008 60
61. RSendAs: Generic, simplified creation of messages CSendUi / ...: Provide UI for creating, editing and sending MTMs Andreas Jakl, 2008 61 Application can use either of these APIs, depending on the required functionality Client SMS MTM MMS MTM POP3 MTM IMAP4 MTM SMTP MTM CBaseMTM: Generic interface to operating on message data(Create messages, reply, add/remove address, body, subject, attachments, …) ProcessBoundary Messaging Server Server
62. Working with Messages [1] Several options available Choose depending on required complexity: Direct use of a specific MTM (e.g. CSmsClientMtm): Allows more control Access to specific, non-generic elements (e.g. number of the SMS Service Center) Generic MTM (CBaseMtm): High-level interface for access to Message Server Entry Defines general access (saving) and individual elements of a message (recipient, subject, text, attachments) Andreas Jakl, 2008 62
63. Working with Messages [2] SendAs-API (RSendAs): Simplifies creating messages Limited subset of MTM functions Wrapper-UI (S60: CSendUi / UIQ: CQikSendAsDialog + CQikSendAsLogic): If message should be created / edited by the user Provides UI controls and command handling for editing messages Andreas Jakl, 2008 63
64. Sending an SMS with SendAs Andreas Jakl, 2008 64 #include <smut.h> // for KUidMsgTypeSMS #include <sendas2.h>// link against sendas2.lib #include <rsendasmessage.h> _LIT(KSMSRecipient, "+436..."); _LIT(KSMSBodyText, "Welcome to the world of Symbian OS"); // Connect to the SendAs-service RSendAssendAs; User::LeaveIfError(sendAs.Connect()); CleanupClosePushL(sendAs); // Create a new message RSendAsMessagesendAsMessage; sendAsMessage.CreateL(sendAs, KUidMsgTypeSMS); CleanupClosePushL(sendAsMessage); // Prepare the message sendAsMessage.AddRecipientL(KSMSRecipient, RSendAsMessage::ESendAsRecipientTo); sendAsMessage.SetBodyTextL(KSMSBodyText); // Send the message // Will display a warning dialog without the required capabilities sendAsMessage.SendMessageAndCloseL(); //sendAsMessage.LaunchEditorAndCloseL(); // Display a message editor CleanupStack::PopAndDestroy(2, &sendAs);
65. Send SMS (MTM) [1] Establish session to the MessageServer Create Client MTM Registry Use this for creating handle to required MTM Create a local index entry with status “in preparation” (TMsvEntry) Construct entry in MessageServer through MTM (CMsvEntry; assigns ID, Store, Folder,…) Add data (text, recipient) Save final message Andreas Jakl, 2008 65
66. Send SMS (MTM) [2] Validate (optional) – Check if message conforms to message type Set SMS Service Center number through MTM settings (specific to SMS, all the other steps are generic!) Switchstatus: “in preparation” “waiting to be sent” Submit asynch. request to send the message Check return value (RunL(), iStatus) Andreas Jakl, 2008 66
67. MMS Andreas Jakl, 2008 67 MMS application MMS server (Message type module) Symbian OS Message Server Symbian OS WAP server MMS Client MTM WAP session protocol (WSP) Wireless transaction protocol (WTP) … only those parts are relevant to your application – behind the scenes a lot more stuff is involved! Wireless transaction layer security (WTLS) Wireless datagram protocol (WDP) Symbian OS Socket server Internet protocol (IP) Network interface manager Connection agent Point-to-point protocol (PPP) Symbian OS Telephony server Symbian OS Serial communications server GPRS telephone module Serial protocol module Serial device drivers GSM protocol stack
69. Cellular Network Access Data-centric Apps usually use higher level APIs (ESock, RConnection, RSocket, ...) Abstracts details of creating connection over cellular network Voice-centric Use telephony subsystem directly Placing outgoing call, answering incoming call, call barring, forwarding, ... VOIP calls not established by ETel (-> SIP / RTP) Andreas Jakl, 2008 69
70. Other uses of the ETel API Monitoring cell ID e.g. for location based games (The Journey) Is the user roaming? Adapt application behavior, e.g. decrease update rate Retrieve IMEI (phone ID) or IMSI (subscriber ID) Lock your application to a specific phone, copy protection Andreas Jakl, 2008 70
71. Telephony Architecture similar to Socket or Comms-Server Generic API Server-side: Plug-in modules (TSY) that allow different hardware without client-side modifications Secure management of multiple (simultaneous) connections through the ETel-Server Andreas Jakl, 2008 71
72. Example – Making a Call Andreas Jakl, 2008 72 #include <Etel3rdParty.h> classCCallDialer : publicCActive { // Omitted construction methods [...] public: // Function for making the initial request voidDialL( constTDesC& aNumber ); private: // Handle completion voidRunL(); private: CTelephony* iTelephony; CTelephony::TCallIdiCallId; }; #include "CallDialer.h" CCallDialer::CCallDialer() : CActive( EPriorityStandard) // Standard priority {} voidCCallDialer::ConstructL() { CActiveScheduler::Add ( this ); // Add to scheduler iTelephony = CTelephony::NewL (); } CCallDialer::~CCallDialer() { Cancel (); // Cancel any request, if outstanding deleteiTelephony; } voidCCallDialer::DoCancel() { iTelephony->CancelAsync ( CTelephony::EDialNewCallCancel); }
73. Example – Making a Call Andreas Jakl, 2008 73 voidCCallDialer::DialL( constTDesC& aNumber) { Cancel (); // Cancel any request, just to be sure CTelephony::TTelNumbertelNumber(aNumber); // Set additional call parameters, e.g. to always send own identity CTelephony::TCallParamsV1 callParams; callParams.iIdRestrict = CTelephony::ESendMyId; CTelephony::TCallParamsV1Pckg callParamsPckg(callParams); // Making a call requires the NetworkServices capability iTelephony->DialNewCall (iStatus, callParamsPckg, telNumber, iCallId); SetActive (); } voidCCallDialer::RunL() { // Handle call dialling completion // e.g.: iObserver.CallDialedL (iStatus.Int ()); }
74. Telephony – Architecture CTelephony provides a simple interface More direct control (Session RTelServer, Subsessions for abstractions): RPhone: Represents the device.Inquiry of status and possibilities RLine: Phone can support 1+ lines.Inquiry of status and possibilities RCall: Line can support 0+ Calls.Tasks like dialling a number, waiting for incoming call, hanging up All three subsessions can inform clients about changes Andreas Jakl, 2008 74
75. Other Services Symbian OS 9 supports several other protocols and services: Web Services / XML SIP (Session Initiation Protocol), e.g. IP-Telephony WLAN WCDMA, EDGE ... Andreas Jakl, 2008 75