qmiinfo: add qmiinfo to test get_ids

qmiinfo is a quick program that, right now, connects to the modem,
gets and displays the ESN, IMEI, and MEID, and disconnects.

Over time, I'll add more of the "get information from the card" calls
to it as a test (both for my own sake and as a debugging utility).

BUG=chromium-os:27303
TEST=will come later

Change-Id: I9a506b26fcdaa3f9099c2c97d27e55512ba5edcb
diff --git a/src/Makefile b/src/Makefile
index b57e48e..56c3aac 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -21,7 +21,8 @@
 	qmidev_unittest
 TESTS = \
 	connect_disconnect_test \
-	get_cid_stress_test
+	get_cid_stress_test \
+	qmiinfo
 
 PC_CFLAGS := $(shell pkg-config --cflags glib-2.0)
 CFLAGS += -fpic -I ../include $(PC_CFLAGS)
@@ -51,12 +52,16 @@
 get_cid_stress_test: get_cid_stress_test.o | libqmi.so
 	$(LINK.c)
 
+qmiinfo: qmiinfo.o | libqmi.so
+	$(LINK.c)
+
 install:
 	install -d $(DESTDIR)$(LIBDIR)
 	install -m755 libqmi.so $(DESTDIR)$(LIBDIR)
 	install -d $(DESTDIR)$(SBINDIR)
 	install -m755 connect_disconnect_test $(DESTDIR)$(SBINDIR)
 	install -m755 get_cid_stress_test $(DESTDIR)$(SBINDIR)
+	install -m755 qmiinfo $(DESTDIR)$(SBINDIR)
 
 clean:
 	rm -f *.o libqmi.so $(UNITTESTS) $(TESTS)
diff --git a/src/qmiinfo.c b/src/qmiinfo.c
new file mode 100644
index 0000000..6577e8b
--- /dev/null
+++ b/src/qmiinfo.c
@@ -0,0 +1,56 @@
+/*
+ * Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include <assert.h>
+#include <stdio.h>
+
+#include <libqmi.h>
+
+static void disconnected(struct qmidev *qmidev, void *data, int status)
+{
+  int *done = data;
+
+  /* unused */
+  qmidev = qmidev;
+
+  assert(status == 0);
+  *done = 1;
+}
+
+static void got_ids(struct qmidev *qmidev, void *data, int status,
+                    const char *esn, const char *imei, const char *meid)
+{
+  assert(status == 0);
+  printf("ESN: %s\nIMEI: %s\nMEID: %s\n", esn, imei, meid);
+  int result = qmidev_disconnect(qmidev, &disconnected, data);
+  assert(result == 0);
+}
+
+static void connected(struct qmidev *qmidev, void *data, int status)
+{
+  assert(status == 0);
+  int result = qmidev_get_ids(qmidev, &got_ids, data);
+  assert(result == 0);
+}
+
+int main(void)
+{
+  int done = 0;
+  int result;
+
+  struct qmidev *qmidev = qmidev_new_file("/dev/cdc-wdm0");
+  assert(qmidev);
+
+  result = qmidev_connect(qmidev, &connected, &done);
+  assert(result == 0);
+
+  while (!done) {
+    result = qmidev_process(qmidev);
+    assert(result == 0);
+  }
+
+  return 0;
+}