skya_product_runtime.c
telephony-skya/drivers/src/skya_product_runtime.c · 15 line(s) · c
#include "skya_product_runtime.h"
#include <errno.h>
#include <string.h>
#include <ctype.h>
static int eqi(const char*a,const char*b){if(!a||!b)return 0;while(*a&&*b){if(tolower((unsigned char)*a)!=tolower((unsigned char)*b))return 0;a++;b++;}return *a==0&&*b==0;}
static int has(const char*s,const char*n){if(!s||!n||!*n)return 0;for(;*s;s++){const char*a=s,*b=n;while(*a&&*b&&tolower((unsigned char)*a)==tolower((unsigned char)*b)){a++;b++;}if(!*b)return 1;}return 0;}
int skya_product_probe(const skya_driver_device*d,const char*v,const char*m){return d&&d->vendor&&d->model&&v&&m&&eqi(d->vendor,v)&&has(d->model,m);}
int skya_product_capabilities(const skya_driver_device*d,const char*v,const char*m,skya_driver_capabilities*out){if(!d||!out||!skya_product_probe(d,v,m))return-EINVAL;memset(out,0,sizeof(*out));out->audio_input=1;out->audio_output=1;out->mute=1;out->volume=1;out->firmware_query=1;out->headset_port=1;out->busylight=1;if(d->transport==SKYA_TRANSPORT_USB_HID){out->call_answer=1;out->call_end=1;out->call_hold=1;out->dialpad=1;}if(d->transport==SKYA_TRANSPORT_SIP||d->transport==SKYA_TRANSPORT_NETWORK){out->call_answer=1;out->call_end=1;out->call_hold=1;out->dialpad=1;out->display=1;}if(d->type==SKYA_DRIVER_BLUETOOTH_HEADSET)out->bluetooth=1;return 0;}
int skya_product_runtime_init(skya_product_runtime*r,const skya_driver_device*d,skya_product_host host,const skya_product_transport*t){if(!r||!d)return-EINVAL;memset(r,0,sizeof(*r));r->device=*d;r->host=host;r->present=1;r->volume=50;if(t)r->transport=*t;return 0;}
int skya_product_runtime_control(skya_product_runtime*r,skya_product_operation op,int32_t value){if(!r||!r->present)return-ENODEV;switch(op){case SKYA_PRODUCT_OP_MUTE:if(value!=0&&value!=1)return-EINVAL;r->muted=value;break;case SKYA_PRODUCT_OP_VOLUME:if(value<0||value>100)return-ERANGE;r->volume=value;break;case SKYA_PRODUCT_OP_ANSWER:r->call_active=1;r->on_hold=0;break;case SKYA_PRODUCT_OP_END:r->call_active=0;r->on_hold=0;break;case SKYA_PRODUCT_OP_HOLD:r->on_hold=value?1:0;break;case SKYA_PRODUCT_OP_BUSYLIGHT:r->busylight=value?1:0;break;case SKYA_PRODUCT_OP_DIAL:if(value<0)return-EINVAL;break;default:return-EINVAL;}if(!r->transport.control)return-ENOTCONN;int rc=r->transport.control(r->transport.ctx,op,value);if(!rc)r->operations++;return rc;}
int skya_product_runtime_firmware(skya_product_runtime*r,char*out,size_t cap){if(!r||!out||!cap)return-EINVAL;if(!r->transport.query_firmware)return-ENOTSUP;return r->transport.query_firmware(r->transport.ctx,out,cap);}
int skya_product_runtime_descriptor(skya_product_runtime*r,uint8_t*out,size_t cap,size_t*len){if(!r||!out||!len)return-EINVAL;if(!r->transport.read_descriptor)return-ENOTSUP;return r->transport.read_descriptor(r->transport.ctx,out,cap,len);}
int skya_product_runtime_hotplug(skya_product_runtime*r,int present){if(!r)return-EINVAL;r->present=present?1:0;return r->transport.hotplug?r->transport.hotplug(r->transport.ctx,r->present):0;}
int skya_product_runtime_reset(skya_product_runtime*r){if(!r)return-EINVAL;if(!r->transport.reset)return-ENOTSUP;int rc=r->transport.reset(r->transport.ctx);if(!rc){r->muted=0;r->volume=50;r->call_active=0;r->on_hold=0;r->busylight=0;r->operations++;}return rc;}