/* 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;
interface nsISmsRequest;
interface nsIDOMMozCellBroadcastMessage;

[scriptable, uuid(0faabc35-644d-4ed5-b109-425280ff1cdf)]
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(a94282b6-da60-4daf-95c1-82ee6889d0df)]
interface nsIRILContactCallback : nsISupports
{
  /**
   * Called when nsIRadioInterfaceLayer is asked to provide ICC contacts.
   *
   * @param errorMsg
   *        error message from RIL.
   * @param contactType
   *        Type of the dialling number, i.e. ADN, FDN.
   * @param contacts
   *        Array of the ICC contacts of the specified type.
   */
  void receiveContactsList(in DOMString errorMsg,
                           in DOMString contactType,
                           in jsval contacts);
};

[scriptable, uuid(c5e31c2c-a6a1-44c3-a30e-7fdfb4dc1750)]
interface nsIRILCellBroadcastCallback : nsISupports
{
  /**
   * Called when a Cell Broadcast message has been received by the network.
   *
   * @param message
   *        The received Cell Broadcast Message.
   */
  void notifyMessageReceived(in nsIDOMMozCellBroadcastMessage message);
};

/**
 * Helper that runs in the content process and exposes information
 * to the DOM.
 */
[scriptable, uuid(8c35c286-7a84-410d-9b36-b15f2cadf78f)]
interface nsIRILContentHelper : nsIMobileConnectionProvider
{
  void registerTelephonyCallback(in nsIRILTelephonyCallback callback);
  void unregisterTelephonyCallback(in nsIRILTelephonyCallback callback);

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

  void registerCellBroadcastCallback(in nsIRILCellBroadcastCallback callback);
  void unregisterCellBroadcastCallback(in nsIRILCellBroadcastCallback callback);

  /**
   * Called when a content process registers receiving unsolicited messages from
   * RadioInterfaceLayer in the chrome process. Only a content process that has
   * the 'telephony' permission is allowed to register. Note that content
   * doesn't need to unregister because the chrome process will remove it from
   * the registration list once the chrome receives a 'child-process-shutdown'
   * message.
   */
  void registerTelephonyMsg();

  /**
   * Called when a content process registers receiving unsolicited messages from
   * RadioInterfaceLayer in the chrome process. Only a content process that has
   * the 'voicemail' permission is allowed to register. Note that content
   * doesn't need to unregister because the chrome process will remove it from
   * the registration list once the chrome receives a 'child-process-shutdown'
   * message.
   */
  void registerVoicemailMsg();

  /**
   * Called when a content process registers receiving unsolicited messages from
   * RadioInterfaceLayer in the chrome process. Only a content process that has
   * the 'cellbroadcast' permission is allowed to register. Note that content
   * doesn't need to unregister because the chrome process will remove it from
   * the registration list once the chrome receives a 'child-process-shutdown'
   * message.
   */
  void registerCellBroadcastMsg();

  /**
   * 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(4efdb1d4-1e49-4f5d-a656-44e6180062a7)]
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;

  /**
   * 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(a90fef2c-44aa-4f2b-a0ee-a590e9dd345e)]
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 setupDataCallByType(in DOMString apntype);
  void deactivateDataCallByType(in DOMString apntype);
  long getDataCallStateByType(in DOMString apntype);
  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 nsISmsRequest request);

  /**
   * ICC-related functionality.
   */

  /**
   * Get ICC Contact List.
   *
   * @param contactType One of the values below.
   *                    "ADN" (Abbreviated Dialling Numbers)
   *                    "FDN" (Fixed Dialling Numbers)
   * @param callback  A nsIRILContactCallback object.
   */
  void getICCContacts(in DOMString contactType,
                      in nsIRILContactCallback callback);
};
