Run the AT modem commands through debugd.

This is necessary because communication with the serial interface
needs root access.

BUG=chrome-os-partner:17809
TEST=tested by issuing the relevant 'modem' commands in crosh
CQ-DEPEND=Iecea0ab5aeb2907ae463fe9a6f1aa83b5632091a

Change-Id: Ic43069080726d62447d5b8d41790ec5340639faa
Reviewed-on: https://gerrit.chromium.org/gerrit/44420
Tested-by: Darin Petkov <petkov@chromium.org>
Reviewed-by: Elly Jones <ellyjones@chromium.org>
Reviewed-by: Jorge Lucangeli Obes <jorgelo@chromium.org>
Commit-Queue: Darin Petkov <petkov@chromium.org>
diff --git a/modem b/modem
index 4b8bc64..0569da6 100755
--- a/modem
+++ b/modem
@@ -325,34 +325,10 @@
   echo "Please reboot (or restart cromo) to use the new config group."
 }
 
-send_at_command() {
-  local modem_tty=/dev/ttyUSB1
-  [ -c "${modem_tty}" ] || error_exit "Missing modem tty device."
+run_modem_command() {
   $(needarg cmd)
-  /usr/sbin/chat -e ABORT '\nERROR' '' "${cmd}" '\nOK' 2> >(tr -s '\n\r') \
-    < "${modem_tty}" > "${modem_tty}"
-}
-
-get_oma_status() {
-  send_at_command 'AT+OMADM=?'
-}
-
-start_oma() {
-  send_at_command 'AT+OMADM=1'
-  send_at_command 'AT+OMADM=2'
-}
-
-get_prl() {
-  send_at_command 'AT$PRL?'
-}
-
-ciprl_update() {
-  send_at_command 'AT+PRL=1'
-  send_at_command 'AT+PRL=2'
-}
-
-get_service() {
-  send_at_command 'AT+SERVICE?'
+  dbus-send --system --print-reply --dest=org.chromium.debugd \
+    /org/chromium/debugd org.chromium.debugd.RunModemCommand "string:${cmd}"
 }
 
 usage() {
@@ -388,7 +364,7 @@
     activate_manual "$@"
     ;;
   ciprl-update)
-    ciprl_update "$@"
+    run_modem_command ciprl-update
     ;;
   connect)
     connect "$@"
@@ -397,13 +373,13 @@
     factory_reset "$@"
     ;;
   get-oma-status)
-    get_oma_status "$@"
+    run_modem_command get-oma-status
     ;;
   get-prl)
-    get_prl "$@"
+    run_modem_command get-prl
     ;;
   get-service)
-    get_service "$@"
+    run_modem_command get-service
     ;;
   reset)
     reset "$@"
@@ -418,7 +394,7 @@
     set_madison_config "$@"
     ;;
   start-oma)
-    start_oma "$@"
+    run_modem_command start-oma
     ;;
   status)
     status "$@"