NTSTATUS EvtDeviceAdd( _In_ WDFDRIVER Driver, _Inout_ PWDFDEVICE_INIT DeviceInit ) { NTSTATUS status; PDEVICE_CONTEXT deviceContext; status = DeviceCreate(Driver, DeviceInit, &deviceContext); if (!NT_SUCCESS(status)) { return status; } status = DeviceConfigure(deviceContext); if (!NT_SUCCESS(status)) { return status; } return status; }
/** * @brief Call back from retargeted operations on the M2M network application. * @param ident the network identifier (i.e. the network name) * @param targetlevel The access right level (i.e. 1, 2 or 3) * @param obix the request content decoded as oBIX buffer. * @param targetid the request URI of the dIa incoming request. * @param reqId the dIa request identifier to provide on completion. */ int CmnNetworkExecuteMethod(char *ident, int targetlevel, void *obix, char *targetid, int tid) { RTL_TRDBG(TRACE_API, "%s\n", __FUNCTION__); NOT_USED(targetlevel); NOT_USED(tid); // Ensure the ident exists Network_t *network = NetworkFindFromName(ident); if (network == NULL) { RTL_TRDBG(TRACE_API, "Network doesn't exist (ident:%s)\n", ident); return -404; } char *ope = rindex(targetid, '/') + 1; if (ope == NULL || *ope == '\0') { RTL_TRDBG(TRACE_API, "Can't read operation\n"); return -404; } if (strcmp(ope, "modbusDeleteNetwork") == 0) { /* No Payload */ NetworkDelete(network); return 0; } else if (strcmp(ope, "modbusAddDevice") == 0) { /* <?xml version="1.0" encoding="UTF-8"?> <obix:obj xmlns:obix="http://obix.org/ns/schema/1.1"> <obix:str name="modbusDeviceName" val="LabjackRoof" /> <obix:str name="modbusDeviceAddress" val="192.1.1.3:502" /> <obix:str name="modbusDeviceDefinition" val="labjack:u9:1" /> </obix:obj> <?xml version="1.0" encoding="UTF-8"?> <obix:obj xmlns:obix="http://obix.org/ns/schema/1.1"> <obix:str name="modbusDeviceName" val="LabjackRoof" /> <obix:str name="modbusDeviceAddress" val="1" /> <obix:str name="modbusDeviceDefinition" val="labjack:u9:1" /> </obix:obj> */ char *modbusDeviceName = (char *) XoNmGetAttr(obix, "wrapper$[name=modbusDeviceName].val", NULL); if (modbusDeviceName == NULL) { RTL_TRDBG(TRACE_API, "Argument 'modbusDeviceName' not found\n"); return -400; } char *modbusDeviceAddress = (char *) XoNmGetAttr(obix, "wrapper$[name=modbusDeviceAddress].val", NULL); if (modbusDeviceAddress == NULL) { RTL_TRDBG(TRACE_API, "Argument 'modbusDeviceAddress' not found\n"); return -400; } char *modbusDeviceDefinition = (char *) XoNmGetAttr(obix, "wrapper$[name=modbusDeviceDefinition].val", NULL); if (modbusDeviceDefinition == NULL) { RTL_TRDBG(TRACE_API, "Argument 'modbusDeviceDefinition' not found\n"); return -400; } Sensor_t *device = DeviceCreate(network, modbusDeviceName, modbusDeviceAddress, modbusDeviceDefinition); if (device == NULL) { return -500; } DeviceDiaCreateNext(device); return 0; } else if (strcmp(ope, "modbusScanNetwork") == 0) { // FFS modbusScanNetwork return -501; } else { RTL_TRDBG(TRACE_API, "Unknown operation '%s' on network\n", ope); return -404; } // Answer a wrong request URI return -404; }