Intrusion Detection in Homogeneous and Heterogeneous Wireless Sensor Networks