#include #include #include #include #include static int incall_handler(struct lgsm_handle *lh, int evt, struct gsmd_evt_auxdata *aux) { printf("EVENT: Incoming call type = %u\n", aux->u.call.type); return 0; } static int clip_handler(struct lgsm_handle *lh, int evt, struct gsmd_evt_auxdata *aux) { printf("EVENT: Incoming call clip = %s\n", aux->u.clip.addr.number); return 0; } static int colp_handler(struct lgsm_handle *lh, int evt, struct gsmd_evt_auxdata *aux) { printf("EVENT: Outgoing call colp = %s\n", aux->u.colp.addr.number); return 0; } static int netreg_handler(struct lgsm_handle *lh, int evt, struct gsmd_evt_auxdata *aux) { printf("EVENT: Netreg "); switch (aux->u.netreg.state) { case 0: printf("not searching for network "); break; case 1: printf("registered (home network) "); break; case 2: printf("searching for network "); break; case 3: printf("registration denied "); break; case 5: printf("registered (roaming) "); break; } if (aux->u.netreg.lac) printf("LocationAreaCode = 0x%04X ", aux->u.netreg.lac); if (aux->u.netreg.ci) printf("CellID = 0x%04X ", aux->u.netreg.ci); printf("\n"); return 0; } static int sigq_handler(struct lgsm_handle *lh, int evt, struct gsmd_evt_auxdata *aux) { printf("EVENT: Signal Quality: %u\n", aux->u.signal.sigq.rssi); return 0; } static const char *cprog_names[] = { [GSMD_CALLPROG_SETUP] = "SETUP", [GSMD_CALLPROG_DISCONNECT] = "DISCONNECT", [GSMD_CALLPROG_ALERT] = "ALERT", [GSMD_CALLPROG_CALL_PROCEED] = "PROCEED", [GSMD_CALLPROG_SYNC] = "SYNC", [GSMD_CALLPROG_PROGRESS] = "PROGRESS", [GSMD_CALLPROG_CONNECTED] = "CONNECTED", [GSMD_CALLPROG_RELEASE] = "RELEASE", [GSMD_CALLPROG_REJECT] = "REJECT", [GSMD_CALLPROG_UNKNOWN] = "UNKNOWN", }; static const char *cdir_names[] = { [GSMD_CALL_DIR_MO] = "Outgoing", [GSMD_CALL_DIR_MT] = "Incoming", [GSMD_CALL_DIR_CCBS] = "CCBS", [GSMD_CALL_DIR_MO_REDIAL] = "Outgoing Redial", }; static int cprog_handler(struct lgsm_handle *lh, int evt, struct gsmd_evt_auxdata *aux) { const char *name, *dir; if (aux->u.call_status.prog >= ARRAY_SIZE(cprog_names)) name = "UNDEFINED"; else name = cprog_names[aux->u.call_status.prog]; if (aux->u.call_status.dir >= ARRAY_SIZE(cdir_names)) dir = ""; else dir = cdir_names[aux->u.call_status.dir]; printf("EVENT: %s Call Progress: %s\n", dir, name); return 0; } int event_init(struct lgsm_handle *lh) { int rc; rc = lgsm_evt_handler_register(lh, GSMD_EVT_IN_CALL, &incall_handler); rc |= lgsm_evt_handler_register(lh, GSMD_EVT_IN_CLIP, &clip_handler); rc |= lgsm_evt_handler_register(lh, GSMD_EVT_OUT_COLP, &colp_handler); rc |= lgsm_evt_handler_register(lh, GSMD_EVT_NETREG, &netreg_handler); rc |= lgsm_evt_handler_register(lh, GSMD_EVT_SIGNAL, &sigq_handler); rc |= lgsm_evt_handler_register(lh, GSMD_EVT_OUT_STATUS, &cprog_handler); return rc; }