/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "nsISupports.idl"
#include "nsIMobileConnectionProvider.idl"

interface nsIDOMMozMobileConnectionInfo;
interface nsIDOMDOMRequest;
interface nsIDOMWindow;
interface nsIDOMMozVoicemailStatus;

[scriptable, uuid(c14c71b8-afba-403b-8320-94593de9380f)]
interface nsIRILTelephonyCallback : nsISupports
{
  /**
   * Notified when a telephony call changes state.
   *
   * @param callIndex
   *        Call identifier assigned by the RIL.
   * @param callState
   *        One of the nsIRadioInterfaceLayer::CALL_STATE_* values.
   * @param number
   *        Number of the other party.
   * @param isActive
   *        Indicates whether this call is the currently active one.
   */
  void callStateChanged(in unsigned long callIndex,
                        in unsigned short callState,
                        in AString number,
                        in boolean isActive);

  /**
   * Called when nsIRILContentHelper is asked to enumerate the current
   * telephony call state (nsIRILContentHelper::enumerateCalls). This is
   * called once per call that is currently managed by the RIL.
   *
   * @param callIndex
   *        Call identifier assigned by the RIL.
   * @param callState
   *        One of the nsIRadioInterfaceLayer::CALL_STATE_* values.
   * @param number
   *        Number of the other party.
   * @param isActive
   *        Indicates whether this call is the active one.
   *
   * @return true to continue enumeration or false to cancel.
   */
  boolean enumerateCallState(in unsigned long callIndex,
                             in unsigned short callState,
                             in AString number,
                             in boolean isActive);

  /**
   * Called when RIL error occurs.
   *
   * @param callIndex
   *        Call identifier assigned by the RIL. -1 if no connection
   * @param error
   *        Error from RIL.
   */
  void notifyError(in long callIndex,
                   in AString error);
};

[scriptable, uuid(521cfe4a-bf79-4134-a9fc-e2242164d657)]
interface nsIRILVoicemailCallback : nsISupports
{
  /**
   * Called when a voicemail notification has been received by the network.
   *
   * @param status
   *        The new voicemail status
   */
  void voicemailNotification(in nsIDOMMozVoicemailStatus status);
};

[scriptable, uuid(1e602d20-d066-4399-8997-daf36b3158ef)]
interface nsIRILDataCallInfo : nsISupports
{
  /**
   * Current data call state, one of the
   * nsINetworkInterface::NETWORK_STATE_* constants.
   */
  readonly attribute unsigned long state;
  readonly attribute AString cid;
  readonly attribute AString apn;
  readonly attribute AString ifname;
  readonly attribute AString ip;
  readonly attribute AString netmask;
  readonly attribute AString broadcast;
  readonly attribute AString gw;
  readonly attribute jsval dns;
};

[scriptable, uuid(5bcac053-c245-46f0-bb45-d0039bfb89f5)]
interface nsIRILDataCallback : nsISupports
{
  /**
   * Notified when a data call changes state.
   *
   * @param dataCall
   *        A nsIRILDataCallInfo object.
   */
  void dataCallStateChanged(in nsIRILDataCallInfo dataCall);

  /**
   * Called when nsIRadioInterfaceLayer is asked to enumerate the current
   * data call state.
   *
   * @param datacalls
   *        Array of nsIRILDataCallInfo objects.
   * @param length
   *        Lenght of the aforementioned array.
   */
  void receiveDataCallList([array,size_is(length)] in nsIRILDataCallInfo dataCalls,
                           in unsigned long length);
};

[scriptable, function, uuid(2bc2f51a-78be-4c0e-95dd-55a3ce2ded40)]
interface nsIRILContactCallback : nsISupports
{
  /**
   * Called when nsIRadioInterfaceLayer is asked to provide ICC contacts.
   *
   * @param type
   *        Type of the dialling number, i.e. ADN, FDN.
   * @param contacts
   *        Array of the ICC contacts of the specified type.
   */
  void receiveContactsList(in DOMString type, in jsval contacts);
};

/**
 * Helper that runs in the content process and exposes information
 * to the DOM.
 */
[scriptable, uuid(31ea634b-e710-49ce-bb7d-bfcbaa40fb00)]
interface nsIRILContentHelper : nsIMobileConnectionProvider
{
  void registerTelephonyCallback(in nsIRILTelephonyCallback callback);
  void unregisterTelephonyCallback(in nsIRILTelephonyCallback callback);

  void registerVoicemailCallback(in nsIRILVoicemailCallback callback);
  void unregisterVoicemailCallback(in nsIRILVoicemailCallback callback);

  /**
   * Will continue calling callback.enumerateCallState until the callback
   * returns false.
   */
  void enumerateCalls(in nsIRILTelephonyCallback callback);

  /**
   * Functionality for making and managing phone calls.
   */
  void dial(in DOMString number);
  void dialEmergency(in DOMString number);
  void hangUp(in unsigned long callIndex);

  void startTone(in DOMString dtmfChar);
  void stopTone();

  void answerCall(in unsigned long callIndex);
  void rejectCall(in unsigned long callIndex);
  void holdCall(in unsigned long callIndex);
  void resumeCall(in unsigned long callIndex);

  attribute bool microphoneMuted;
  attribute bool speakerEnabled;

  readonly attribute nsIDOMMozVoicemailStatus voicemailStatus;
  readonly attribute DOMString voicemailNumber;
  readonly attribute DOMString voicemailDisplayName;
};

[scriptable, uuid(fd9e8b38-b839-4d56-8482-3bf1f5c8f2ee)]
interface nsIICCRecords : nsISupports
{
  /**
   * Mobile Subscriber ISDN Number
   */
  readonly attribute DOMString msisdn;

  /**
   * Administrative Data
   */
  readonly attribute jsval ad;

  /**
   * International Mobile Subscriber Identity
   */
  readonly attribute DOMString imsi;

  /**
   * Mobile Country Code
   */
  readonly attribute unsigned short mcc;

  /**
   * Mobile Network Code
   */
  readonly attribute unsigned short mnc;

  /**
   * USIM Service Table
   */
  readonly attribute jsval ust;

  /**
   * Abbreviated dialling numbers
   */
  readonly attribute jsval adn;

  /**
   * Fixed Dialling Numbers
   */
  readonly attribute jsval fdn;
};

[scriptable, uuid(e6dc89f2-0d4e-46fc-902c-cfeeaee15e40)]
interface nsIRilContext : nsISupports
{
  readonly attribute DOMString radioState;

  readonly attribute DOMString cardState;

  readonly attribute nsIICCRecords icc;

  readonly attribute nsIDOMMozMobileConnectionInfo voice;

  readonly attribute nsIDOMMozMobileConnectionInfo data;
};

[scriptable, uuid(8b649965-6687-46a8-88fa-a5495ce90735)]
interface nsIRadioInterfaceLayer : nsISupports
{
  const unsigned short CALL_STATE_UNKNOWN = 0;
  const unsigned short CALL_STATE_DIALING = 1;
  const unsigned short CALL_STATE_ALERTING = 2;
  const unsigned short CALL_STATE_BUSY = 3;
  const unsigned short CALL_STATE_CONNECTING = 4;
  const unsigned short CALL_STATE_CONNECTED = 5;
  const unsigned short CALL_STATE_HOLDING = 6;
  const unsigned short CALL_STATE_HELD = 7;
  const unsigned short CALL_STATE_RESUMING = 8;
  const unsigned short CALL_STATE_DISCONNECTING = 9;
  const unsigned short CALL_STATE_DISCONNECTED = 10;
  const unsigned short CALL_STATE_INCOMING = 11;

  /**
   * Activates or deactivates radio power.
   */
  void setRadioEnabled(in bool value);

  readonly attribute nsIRilContext rilContext;

  /**
   * PDP APIs
   */
  void setupDataCall(in long radioTech,
                     in DOMString apn,
                     in DOMString user,
                     in DOMString passwd,
                     in long chappap,
                     in DOMString pdptype);
  void deactivateDataCall(in DOMString cid,
                          in DOMString reason);
  void getDataCallList();

  void registerDataCallCallback(in nsIRILDataCallback callback);
  void unregisterDataCallCallback(in nsIRILDataCallback callback);

  /**
   * SMS-related functionality.
   */
  unsigned short getNumberOfMessagesForText(in DOMString text);
  void sendSMS(in DOMString number,
               in DOMString message,
               in long requestId,
               in unsigned long long processId);

  /**
   * ICC-related functionality.
   */
  void getICCContacts(in DOMString type, in nsIRILContactCallback callback);
};
