- int mute = 0;
- long vol = 0, max = 0, min = 0;
-
- /* get volume from alsa */
- snd_mixer_t *handle;
- snd_mixer_elem_t *pcm_mixer, *mas_mixer;
- snd_mixer_selem_id_t *vol_info, *mute_info;
- snd_mixer_open(&handle, 0);
- snd_mixer_attach(handle, soundcard);
- snd_mixer_selem_register(handle, NULL, NULL);
- snd_mixer_load(handle);
- snd_mixer_selem_id_malloc(&vol_info);
- snd_mixer_selem_id_malloc(&mute_info);
- snd_mixer_selem_id_set_name(vol_info, channel);
- snd_mixer_selem_id_set_name(mute_info, channel);
- pcm_mixer = snd_mixer_find_selem(handle, vol_info);
- mas_mixer = snd_mixer_find_selem(handle, mute_info);
- snd_mixer_selem_get_playback_volume_range((snd_mixer_elem_t *)pcm_mixer,
- &min, &max);
- snd_mixer_selem_get_playback_volume((snd_mixer_elem_t *)pcm_mixer,
- SND_MIXER_SCHN_MONO, &vol);
- snd_mixer_selem_get_playback_switch(mas_mixer, SND_MIXER_SCHN_MONO,
- &mute);
- if (vol_info)
- snd_mixer_selem_id_free(vol_info);
- if (mute_info)
- snd_mixer_selem_id_free(mute_info);
- if (handle)
- snd_mixer_close(handle);
-
- /* return the string (mute) */
- if (!mute)
- return "mute";
- else
- return smprintf("%d%%", (vol * 100) / max);
+ int strength;
+ char buf[255];
+ char *datastart;
+ char path[64];
+ char status[5];
+ char needle[strlen(wificard)+2];
+ FILE *fp;
+
+ strlcpy(path, "/sys/class/net/", sizeof(path));
+ strlcat(path, wificard, sizeof(path));
+ strlcat(path, "/operstate", sizeof(path));
+
+ fp = fopen(path, "r");
+
+ if(fp == NULL) {
+ fprintf(stderr, "Error opening wifi operstate file: %s\n",
+ strerror(errno));
+ return smprintf(UNKNOWN_STR);
+ }
+
+ fgets(status, 5, fp);
+ fclose(fp);
+ if(strcmp(status, "up\n") != 0)
+ return smprintf(UNKNOWN_STR);
+
+ fp = fopen("/proc/net/wireless", "r");
+ if (fp == NULL) {
+ fprintf(stderr, "Error opening wireless file: %s\n",
+ strerror(errno));
+ return smprintf(UNKNOWN_STR);
+ }
+
+ strlcpy(needle, wificard, sizeof(needle));
+ strlcat(needle, ":", sizeof(needle));
+ fgets(buf, sizeof(buf), fp);
+ fgets(buf, sizeof(buf), fp);
+ fgets(buf, sizeof(buf), fp);
+
+ datastart = strstr(buf, needle);
+ if (datastart != NULL) {
+ datastart = strstr(buf, ":");
+ sscanf(datastart + 1, " %*d %d %*d %*d %*d %*d %*d %*d %*d %*d", &strength);
+ }
+
+ fclose(fp);
+ return smprintf("%d%%", strength);